-5

I implemented some cpu scheduling algorithm.and i want to show it in windows form application in c# graphically but i don't know how?
example:
I have these processes:

p1,p2,p3,p4,p5,p6,p7,p8,p9,...  

p2 do its process before p1,and p1 before p6 and p6 before p3 and...
I want something like this to show it for me:
https://i.stack.imgur.com/zEWbG.jpg
also each process length change based on its own process time, and show process start time and end time too.
How can I make something like that?
thank u.

akuzma
  • 1,592
  • 6
  • 22
  • 49
Nima
  • 45
  • 6

1 Answers1

0

I would recommend using WPF. You could achieve this many different ways.

One example is a WPF Grid with multiple columns. You can set the width of the column as a proportion. Eg A width of "3*" would indicate a process that takes half the time as a width of "6*"

<Window x:Class="WpfApplication3.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid Name="MainGrid" Height="80">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="1*"></ColumnDefinition>
        <ColumnDefinition Width="2*"></ColumnDefinition>
        <ColumnDefinition Width="4*"></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <Rectangle Fill="LightBlue"/>
    <Rectangle Grid.Column="1" Fill="LightGreen"/>
    <Rectangle Grid.Column="2" Fill="LightPink"/>
    <Label HorizontalAlignment="Center" VerticalAlignment="Center">P2</Label>
    <Label Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center">P1</Label>
    <Label Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center">P6</Label>
</Grid>
</Window>

This XAML code would produce this.

http://img835.imageshack.us/img835/4742/picturelx.png

You could programatically add columns using C# code-behind like this.

 private void AddColumn()
    {
        //Create the columndefinition with a width of "3*"
        ColumnDefinition column = new ColumnDefinition();
        column.Width = new GridLength(3, GridUnitType.Star);

        //Add the column to the grid
        MainGrid.ColumnDefinitions.Add(column);

        //Create the rectangle
        Rectangle rect = new Rectangle();
        rect.Fill = new SolidColorBrush(Colors.Beige);
        MainGrid.Children.Add(rect);
        Grid.SetColumn(rect, 3);

        //Create the label
        Label label = new Label();
        label.VerticalAlignment = System.Windows.VerticalAlignment.Center;
        label.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
        label.Content = "P4";
        MainGrid.Children.Add(label);
        Grid.SetColumn(label, 3);

    }
alexwiese
  • 13
  • 2