Re: GDI+ on Windows Forms
From: R K (magraph_at_hotmail.com)
Date: 06/10/04
- Next message: Stephan Steiner: "Re: alpha channels in icons"
- Previous message: Jon Skeet [C# MVP]: "Re: dataset and locks"
- In reply to: Morten Wennevik: "Re: GDI+ on Windows Forms"
- Next in thread: Morten Wennevik: "Re: GDI+ on Windows Forms"
- Reply: Morten Wennevik: "Re: GDI+ on Windows Forms"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 10 Jun 2004 00:24:45 -0700
Hi Morten,
Thanks for the suggestions. So I'm essentially printing a report for
viewing based on processing an XML file. There is no interaction with the
elements in the report once it has been drawn, so I don't need to handle any
selected item. Also if I invalidate the listbox, wouldn't I need to
reprocess the XML file again to re-draw everything . Need some
clarifications here. Also since the elements in the listbox is around 120
which does not fit the screen, wouldn't I need to handle the scroll bar
events ..etc which I'm trying to avoid writing. Or am I stuck with
handling the resize, scrolbar, move events and redrawing each time? That's
really a pain for doing a static report.
Thanks,
R.K.
"Morten Wennevik" <MortenWennevik@hotmail.com> wrote in message
news:opr9c6yvfhklbvpo@morten_x.edunord...
> Hi R.K.
>
> If you only need to draw the items as a list, you can use a ListBox.
> Set the ListBox's DrawMode to OwnerDrawFixed or OwnerDrawVariable (based
> on wether or not the height of the items change, usually fixed is what you
> would pick). Create an event handler for the DrawItem event.
> In that event, determine which element is currently to be drawn (the event
> will fire for each element, so you only need to draw one at a time). The
> position to draw is stored in the Bounds property of the event. Use
> DrawString to write the element name, and any other graphics method as you
> need. Btw. you can use a ComboBox the exact same way, and the currently
> selected item will be drawn the same way in the edit box (looks very
> professional :P)
>
> // This sample will fill 4 lines with various objects
> private void listBox1_DrawItem(object sender,
> System.Windows.Forms.DrawItemEventArgs e)
> {
> // If you want to select items, you need to indicate the selected item by
> drawing the background
> // SystemBrushes.HighLight is the selection color, and changes with window
> settings.
> if(e.Index == listBox1.SelectedIndex)
> e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds.X, e.Bounds.Y,
> e.Bounds.Width, e.Bounds.Height);
>
> // I used a switch to determine what to draw, but you can use anything you
> want.
> // The listbox needs to be filled with items, even though they won't be
> shown,
> // or you won't get an event to draw the items.
> switch(e.Index)
> {
> case 0:
> e.Graphics.FillRectangle(Brushes.BlueViolet, e.Bounds.X, e.Bounds.Y, 10,
> 10);
> break;
> case 1:
> e.Graphics.DrawPie(Pens.HotPink, e.Bounds.X, e.Bounds.Y, 10, 10, 0, 90);
> break;
> case 2:
> e.Graphics.DrawString("Hello World", this.Font, Brushes.Black, e.Bounds.X,
> e.Bounds.Y);
> break;
> case 3:
> e.Graphics.DrawLine(Pens.OldLace, e.Bounds.X, e.Bounds.Y + 16, e.Bounds.X
> + 50, e.Bounds.Y);
> break;
> }
> }
>
> // Causes everything to be redrawn, needed to clear previously selected
> items.
> // There are probably a more efficient ways, but this is the easiest.
> private void listBox1_SelectedIndexChanged(object sender, System.EventArgs
> e)
> {
> listBox1.Invalidate(); }
>
> --
> Happy coding!
> Morten Wennevik [C# MVP]
- Next message: Stephan Steiner: "Re: alpha channels in icons"
- Previous message: Jon Skeet [C# MVP]: "Re: dataset and locks"
- In reply to: Morten Wennevik: "Re: GDI+ on Windows Forms"
- Next in thread: Morten Wennevik: "Re: GDI+ on Windows Forms"
- Reply: Morten Wennevik: "Re: GDI+ on Windows Forms"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|