Re: GDI+ on Windows Forms

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: R K (magraph_at_hotmail.com)
Date: 06/10/04


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]



Relevant Pages

  • Re: GDI+ on Windows Forms
    ... > elements in the report once it has been drawn, so I don't need to handle any ... > reprocess the XML file again to re-draw everything. ... The DrawItem event will tell which item to draw and where to draw it. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: My earlier post was Horizontal Line
    ... The code below is the exact of my Report module. ... It can draw the table ... starting point for the line or rectangle. ... QBColor function to specify the color. ...
    (microsoft.public.access.formscoding)
  • Re: Console-ish output in a browser, how?
    ... That's a good question--I've never had a great deal of luck styling ListBox controls. ... "Dispatching report to user email ...."); ... "Dispatching the final report to user email ..."); ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Using List Box to control Records in a Report
    ... The following is the command button for adding the current record to the ... I then use the stWhere in the Print report command buttons onclick event. ... Dim stPrintList As String ... IsSelected field in the table that is the source for your listbox. ...
    (microsoft.public.access.formscoding)
  • Re: Multiselect lstbox vs Continuous Sub?
    ... So I have put together a form with a listbox on it. ... Private Sub cmdPrintGoldenrod_Click ... For Each itm In Me.lstGoldenTwps.ItemsSelected ... I am basically filtering the report based on the bound ...
    (microsoft.public.access.forms)