I have a PictureBox that draws an image and then a rectangle. However, annoyingly, any other window that I put over the rectangle causes it not to redraw. (I can cut out half of the rectangle by opening Notepad and placing it over half of it, or all of it by minimizing and then maximizing)
Here is my code: - private void Refresh_PictureBox()
-
{
-
Graphics g = pictureBox1.CreateGraphics();
-
-
g.DrawImage(pictureBox1.Image,
-
new Rectangle(0, 0, pictureBox1.Right - vScrollBar1.Width,
-
pictureBox1.Bottom - hScrollBar1.Height),
-
new Rectangle(hScrollBar1.Value, vScrollBar1.Value,
-
pictureBox1.Right - vScrollBar1.Width,
-
pictureBox1.Bottom - hScrollBar1.Height),
-
GraphicsUnit.Pixel);
-
-
foreach (NPC npc in NPCs)
-
{
-
if (npc.ID == NPCSelectedID)
-
{
-
Point p1 = new Point(npc.startx - hScrollBar1.Value, npc.starty - vScrollBar1.Value);
-
g.DrawRectangle(new Pen(Color.Red), new Rectangle(p1, new Size(npc.width, npc.height)));
-
}
-
}
-
-
pictureBox1.Update();
-
-
g.Dispose();
-
}
Don't worry about the values of the coordinates or the NPC stuff. There must be something wrong with my ordering or my structuring of creating graphics specifically.
This function gets called on HandleScroll and Click for the picturebox, as well as on the form Resize. And, certainly enough, the rectangle comes back when any of these events are done. But why would the rectangle disappear and not the rest of the image? That's what bothers me.
If you would like to see more code just say so.
Thanks,
Scott
4 1729
Attach a handler to the Paint event and put your code in there.
Thanks for the advice.
It's weird now. Now it does redraw, but only when I move the Notepad window slowly enough. If I move it fast, it never comes back.
Changing the actual pixels of the picturebox's image is very rigid, but also very sluggish. I'd rather use the Draw methods of the Graphics class, but I'm still having problems with redrawing. Any ideas to get it close to as rigid as changing the actual pixels?
Any more help would be appreciated,
Scott
I just went down to the byte level of the image instead of the sluggish Get and SetPixel(), and now it works much faster. If anyone wants help with how I did this, feel free to ask.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Pavan Arise |
last post by:
Dear all..
I have a picturebox filled on a form. The picturebox has some
graphics displayed on it.I was trying to save the picturebox, but
continuesly failed to do so. I am clueless of why it is...
|
by: akh |
last post by:
I want to use de Drag and Drop ´s event to move a picture box from a
form and within a Picture Box.
But I have behaviour if the MyPBox As PictureBox as the Globale
varible or not
Thanks for...
|
by: Mattbooty |
last post by:
Hello,
Not sure if anyone else has seen this bug, but I have a form where
the entire form is covered with a picturebox. The picturebox has a
mouseup event. I also have an open file dialog for...
|
by: munglet |
last post by:
Is there anyway to get a picturebox to recieve focus?
I ask because I implemented a "delete" button in a picturebox (due to
size constraints), but now due to accessibility reasons I need to be...
|
by: kebalex |
last post by:
Hi,
I have an app (written in .NET 2.0) which updates a picturebox
according to some user input (a slider control). when the user makes a
change i loop through all of the pixels, do a...
|
by: munibe |
last post by:
Hi, i have a problem about picturebox control. if you may help me, i will be so happy. i have a picturebox named pic_map, and i added a button named customer_button, my wish is to add a new small...
|
by: Jim McGivney |
last post by:
In C# on Form1 I genetate an array of PictureBoxes and populate each with an
image as seen in the code below.
Later on I want to access a specific PictureBox to change its image, but I
keep...
|
by: gerardianlewis |
last post by:
Any help appreciated.
(VB.NET under XP and Vista, SP1 installed)
My code, inherited from a VB6 version of an app that ran under W98,
loads an image from a file into a PictureBox. The user may...
|
by: AWW |
last post by:
XP VB 2005 running an example from help that creates a picturebox in
code - the picturebox is not created.
If I comment out the "Dim Box as New PictureBox" and create it in
Design mode - the...
|
by: leshka82 |
last post by:
I have recently designed a Winform Image drag & drop utility. The approach I took was to have a Panel control serve as a destination for multiple file drop. Once the user dragged & dropped the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |