Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WPF - Drawing

Status
Not open for further replies.

kristofdielis

Programmer
Sep 1, 2011
25
0
0
Hi,

Is there some way to draw with WPF, like you could with GDI?

I mean, not add a rectangle object to a stackpanel (which is how it's apparently often done), but really draw a rectangle or whatever, on the surface of a control, at a specified point.

I mean like it was in 'the old days':

Code:
private void Form1_Paint(object sender, PaintEventArgs e)
{
    Graphics gr = e.Graphics;

    for (int row = 0; row < 5; row++)
    {
        for (int col = 0; col < 5; col++)
        {
            gr.DrawRectangle(new Pen(Brushes.Black), new Rectangle(new Point(col * 50, row * 50), new Size(50, 50)));
        }
    }
}

Is there a workable alternative in WPF?


I don't want something like this:

Code:
for (int r = 0; r < this.Height; r++)
{
    StackPanel rowStackPanel = new StackPanel();

    for (int c = 0; c < this.Width; c++)
    {
        Rectangle rect = new Rectangle();
        ...
        rowStackPanel.Children.Add(rect);
    }
    baseControl.Children.Add(rowStackPanel);
}

While this 'works', this approach will prove a serious pain later on.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top