Note that there are some explanatory texts on larger screens.

plurals
  1. POScreen not redrawing until end of mousesup event handler
    primarykey
    data
    text
    <p>Ok, I'm having an issue that I'm not even sure exactly what is happening. Basically: I have a mouseup event for clicking on a button. That event will remove 1 button and physically move all the buttons on the screen to fill the gap. So if you have 2 rows of 2 buttons</p> <pre><code>Button1 Button2 Button3 Button4 </code></pre> <p>and you click Button1, it moves the last 3 so you now have</p> <pre><code>Button2 Button3 Button4 </code></pre> <p>Ok, so, at the end of this event handler it takes a screenshot and saves it (replacing the previous image of buttons 1-4 with the new image of buttons 2-4).</p> <p>The event handler looks like this</p> <pre><code> public void Handle_Button_MouseUp(object sender, MouseEventArgs e) { //Get rid of the button that was clicked ...some unnecessary to the question code here... //Rearrange the remaining buttons to fill the gap Rearrange_Buttons_In_Tray(element); //Save the screenshot imageBox.Image = SavePanel1Screenshot(); } </code></pre> <p>The screenshot code is</p> <pre><code> public Image SavePanel1Screenshot() { int BorderWidth = (this.Width - this.ClientSize.Width) / 2; int TitlebarHeight = this.Height - this.ClientSize.Height - BorderWidth; Rectangle rect = new Rectangle(0, 0, panel1.Width, panel1.Height); Bitmap bmp = new Bitmap(panel1.Width, panel1.Height, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bmp); g.CopyFromScreen(this.Left + panel1.Left + BorderWidth, this.Top + panel1.Top + TitlebarHeight, 0, 0, bmp.Size, CopyPixelOperation.SourceCopy); Image screenShot; screenShot = (Image)bmp; return screenShot; } </code></pre> <p>.</p> <pre><code> public void Rearrange_Buttons_In_Tray(int element) { for (int i = element; i &lt; buttonList.Count; i++) { Place_Button_In_Tray(buttonList[i].buttonSaved, i, true); buttonList[i].element = i; } } </code></pre> <p>Cleaned out some unnecessary to the question parts to avoid clutter. Sorry for the messed up indentation. NOTE: The buttons are not IN the panel, just on top of it. I just use the panel for measurement and aesthetic purposes</p> <pre><code>private void Place_Button_In_Tray(Button button, int element, bool isReArrange) { button.Width = bigButtonWidth; button.Height = bigButtonHeight; Image buttonImage = button.Image; int numButtonsHoriz = panel1.Width / button.Width; int numButtonsVerti = panel1.Height / button.Height; int extraSpaceHoriz = (panel1.Width % button.Width) / (numButtonsHoriz); int extraSpaceVerti = (panel1.Height % button.Height) / numButtonsHoriz; int buttonCount; if (!isReArrange) buttonCount = buttonList.Count - 1; else buttonCount = element; if ((buttonCount) &lt; numButtonsHoriz) { button.Location = new Point(panel1MinX + (button.Width * (buttonCount)) + extraSpaceHoriz, (panel1MinY + extraSpaceVerti)); } else { int newLine = (buttonCount) % numButtonsHoriz; button.Location = new Point(panel1MinX + (button.Width * (newLine)) + extraSpaceHoriz, ((panel1MinY + extraSpaceVerti) + (button.Height * ((buttonCount) / 2) - ((buttonCount) % 2)))); } </code></pre> <p>And now my problem: The image is of a blank screen. It's not that it isn't taking the picture- it's taking the picture before buttons 2-4 are visible on the screen (I can visibly see this happen as I step through the program. At the time the screenshot is taken, the screen is completely blank. Only after it takes do the buttons reappear on the screen)! For some reason, they are not rendering until AFTER the event handler is finished. Once the final piece of code in the event handler is done (the screenshot saving), the buttons all reappear in their respective spots, despite the fact that the visibility of the buttons is not modified at all during this entire process (thus they remain visible the entire time).</p> <p>I'm a little confused as to what exactly is happening and, more importantly, how to go about getting that screenshot after the event handler takes place. >_> Does anyone have any suggestions on what might be going on and, more importantly, how to get that screenshot?</p> <p>EDIT: My description is somewhat difficult to understand. I do apologize. It's hard to articulate exactly what I'm trying to do and what is happening. Here's a more compact and to the point version:</p> <p>Basically, I'm only trying to hide 1 button out of 4. The other 3 on the screen are moved to new locations. For some reason, when they get moved, they vanish from the screen. They don't reappear until after the mouseup function completes, despite me never having modified whether they are visible or not. I only change their location. I want the screenshot to contain those 3 buttons, but for some reason they aren't popping back into existence until after the entire mouseup function ends. >_> So my screenshot is of an empty screen, devoid of buttons</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload