-5

我实现了一些 cpu 调度算法。我想以图形方式在 c# 中的 Windows 窗体应用程序中显示它,但我不知道如何?
示例:
我有这些过程:

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

p2 在 p1 之前执行它的过程,p1 在 p6 之前和 p6 在 p3 之前执行它......
我想要这样的东西给我看:http:
//i.stack.imgur.com/zEWbG.jpg
每个进程长度也会发生变化根据自己的进程时间,并显示进程的开始时间和结束时间。
我怎样才能做出这样的事情?
感谢你。

4

1 回答 1

0

我建议使用 WPF。您可以通过许多不同的方式实现这一目标。

一个示例是具有多列的 WPF 网格。您可以将列的宽度设置为比例。例如,“3*”的宽度表示一个进程花费的时间是“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>

这个 XAML 代码会产生这个。

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

您可以像这样使用 C# 代码隐藏以编程方式添加列。

 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);

    }
于 2012-05-24T12:21:31.373 回答