0

I am developing a windows mobile application for a warehouse. Since the base functionalities have been achieved, I'm working on improving the overall appearance of the application. I'm struggling with few things, and I'd greatly appreciate any help (I'm fairly new to C#, but willing to learn :-).

First of all, I cannot get the overridden OnPaint method to work, not even on the emulator, so I guess I am missing something. Do I need to do anything else than this ? ::

      public partial class Form1 : Form {
         protected override void OnPaint(PaintEventArgs e) {
       base.OnPaint(e);
      /*some basic painting here */
      }}

Second problem originated when I tried to make a listbox selectable "as a one". I don't want the user to click on particular items in it, just a whole listbox. To give you some idea, I want to display a few of listboxes like this one in a list :

multiline_listbox

Is there a way to make them selectable like a normal items in the List?

I couldn't work this one out, so I've tried different approach --> make a bitmap out of those listboxes, and load the bitmaps in a list.

Since compact framework doesn't have built-in neat methods like entity does (DrawToBitmap), I tried this approach (Pocket PC: Draw control to bitmap), but it did not do any good - after getting this to 'work', it changes nothing. I also tried this, from a code snippet that used a screen capture, with no success either.

      System.Drawing.Bitmap destinationBmp = new System.Drawing.Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, 
             System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);

         System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(destinationBmp);
         GraphicsEx gx = GraphicsEx.FromGraphics(g);
         //gx.CopyFromScreen(0, 0, 0, 0, Forms.Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
         //gx.CopyFromScreen(0, hehe.Top, 0, hehe.Bottom + 10, hehe.Size, CopyPixelOperation.SourceCopy);

         gx.CopyGraphics(listbox, listbox.Bounds);
         g.DrawImage(destinationBmp, 0, 200);

What am I missing? Or maybe is a there a better way to do this?

Community
  • 1
  • 1
Luntri
  • 610
  • 1
  • 8
  • 22

1 Answers1

1

You can create what is called an owner-drawn list box. You are in control of the drawing, and can draw multiple lines of text in one list item for the user to click on. I think this will give you the result you want if I am understanding your question correctly.

Here is a MSDN link walking you through making an owner drawn list box with the Compact Framework.

If that doesn't work out for you then you could create a custom control very similar to the WPF StackPanel object. In case you're not familiar, the StackPanel allows you to add child controls to it. The StackPanel "stacks" those children controls horizontally or vertically. If you implemented scrolling and selection you'd have a poor mans list box which allows you to append variable height custom controls to each list box item instead of a simple string. I would recommend seeing if owner draw works for you first though since it involves writing much less code.

Trevor Balcom
  • 3,766
  • 2
  • 32
  • 51
  • That was the approach I ended up using, but I still can't get the OnPaint override to work for no apparent reason :( – Luntri Oct 17 '14 at 09:38