473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

A redraw problem which is perplexing me

Paul Johnson
Hi,

I have a simple winform which creates has in it a NumericUpDown, two group boxes and two buttons. The code then dynamically inserts a number of NumberBox objects into one group box and a pile of labels into the other.

(A numberbox is just an overloaded TextBox - details are at http://www.all-the-johnsons.co.uk/csharp/numberbox.html)

If I click the NumericUpDown, the code inserts new boxes and also reduces it as expected. However, if I click once to create 3 boxes and then go back down to 2, half of the third row still remains and I have no idea why!

NumericUpDown goes from 3 to 6, no decimals

Expand|Select|Wrap|Line Numbers
  1.         private void numericUpDown1_ValueChanged(object sender, EventArgs e)
  2.         {
  3.             drawBoxes((int)numericUpDown1.Value);
  4.         }
  5.  
  6.         private void drawBoxes(int number)
  7.         {
  8.             int ar = number;
  9.             int b = ar;
  10.             int p = 0; // position
  11.             int r = 0; // current row
  12.             ar = Convert.ToInt32(Math.Pow(ar, 2));
  13.             NumberBox[] tmp = new NumberBox[ar]; // do it for the smallest size
  14.             Label[] lbl = new Label[ar];
  15.             int t = 0;
  16.             for (int n = 0; n < ar; ++n)
  17.             {
  18.                 tmp[n] = new NumberBox();
  19.                 tmp[n].Location = new System.Drawing.Point(7 + p, 20 + (26 * r));
  20.                 tmp[n].Name = "numberBox" + n.ToString();
  21.                 tmp[n].Size = new System.Drawing.Size(42, 20);
  22.                 tmp[n].TabIndex = n;
  23.                 groupBox1.Controls.Add(tmp[n]);
  24.  
  25.                 lbl[n] = new Label();
  26.                 lbl[n].Location = new System.Drawing.Point(7 + p, 20 + (26 * r));
  27.                 lbl[n].Name = "label" + n.ToString();
  28.                 lbl[n].Text = "0";
  29.                 lbl[n].Size = new System.Drawing.Size(42, 20);
  30.                 lbl[n].TabIndex = n + ar;
  31.                 groupBox2.Controls.Add(lbl[n]);
  32.  
  33.                 p += 48;
  34.                 if (t + 1 != b)
  35.                     t++;
  36.                 else
  37.                 {
  38.                     t = 0;
  39.                     r++;
  40.                     p = 0;
  41.                 }
  42.             }
  43.             int z = 8 + b * 48;
  44.             int y = 8 + (b * 26) + 16;
  45.             groupBox1.Size = new System.Drawing.Size(z, y);
  46.             groupBox2.Location = new System.Drawing.Point(32 + b * 48, 43);
  47.             groupBox2.Size = new System.Drawing.Size(z, y);
  48.             this.clear.Location = new System.Drawing.Point(16, y + 48);
  49.             this.calc.Location = new System.Drawing.Point(97, y + 48);
  50.             ClientSize = new System.Drawing.Size(z * 2 + 32, y + 80);
  51.             nbArray = tmp; // global
  52.             rdArray = lbl; // global
  53.         }
  54.  
I've gone through the code with the debugger, but can't spot anything out of the ordindary. I've also tried adding an Invalidate() at the end of the method, but still it gives the half box.

The attached screenshot illustrates the problem, look above the buttons. The numberbox gadgets aren't there (I can't tab onto them or click in them), but they remain on screen.

Any help here would be appreciated

Paul
Attached Images
File Type: jpg gausbug.JPG (17.9 KB, 145 views)
Oct 7 '11 #1
1 1442
Sorted it.

Needed groupBox1.Controls.Remove.

D'oh!
Oct 8 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Peter | last post by:
I want to draw some lines on a widget. This works ok, but when I want to redraw, the old lines are still there. How do I clear or refresh the widget, so I can draw a new set of lines? Code...
0
by: PHH | last post by:
Help me, please, When I redraw a ListviewItem in Listview (redraw items with icon and text columms). I used SetStyle(ControlStyle.UserPaint, true) function. And I redraw finish and run...
0
by: WHITETIGER | last post by:
Help me, please, When I redraw a ListviewItem in Listview (redraw items with icon and text columms). I used SetStyle(ControlStyle.UserPaint, true) function. And I redraw finish and run...
2
by: ch424 | last post by:
Hi, Does anybody know the fastest way to trigger a DrawingArea redaw in pygtk? At the moment, I'm using a bit of a hack: def redraw(self): self.area.hide() self.area.show() Is there a...
1
by: kiplring | last post by:
I wrote a program which draw a dancer at cornor of desktop. ( I Accessed through hDC) But It has a problem. I remains all trait at the desktop until I invoke any Redraw( Refresh) action - click,...
5
by: CroDude | last post by:
Hi all! I've made a simple control derived from a panel class which draws gradient in a overrided OnPaintBackground event. Well, I know that I need to redraw control when it's resized by...
1
by: shrewdmonkey | last post by:
Hi all, I'm new to this .NET thing and I was wondering if there is any way to make a splitter control redraw its affected controls while it is being dragged as opposed to when the mouse button...
0
by: Dean Earley | last post by:
Hi all. I have just added translucency to one of my applications using the layered windows API, but I have come across a redraw problem. Unfortunately, I cant reproduce this in a standalone...
2
by: diogoko | last post by:
I have some code like: try { someButton.disabled = true; cpuIntensiveCode(); } finally { someButton.disabled = false; } The problem is that someButton is never disabled, because the browser
0
by: jillybean | last post by:
I am trying to find a way to read in a .bmp file, get the x,y points and then redraw the image by connecting the dots. I can get the dots, but I just don't know how they are relative to one another...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.