I've little question to ask.
Let's say I've written an ellipse on pictureBox, then clicked a button. I want pictureBox to refresh itself.
I've tried PictureBox.Invalidate(), but could'nt made it.
My best regards...
Try the method PictureBox.Refresh() (inherited from Control).
Have you tried PictureBox.Update(); ? Or try something like this http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.image.aspx
There are a couple ways to update the PictureBox, and the method you use makes a difference if you have some lag. I had a program that drew typed characters in a PictureBox, and the keystroke processing was slow so when I typed fast it would lag.
If I pictureBox.Refresh(); after each keystroke, then that refreshes the picture immediately after the keystroke is processed, no matter what. This way, when I typed fast I could see the PictureBox trying to catch up with me as it drew each character.
If instead I pictureBox.Invalidate();, then that refreshes the picture too, but only when the system has some free time. This way, when I typed fast I saw nothing happening while the system tried to catch up, and then everything I'd typed suddenly appeared.
Usually Refresh is better, but here's an article that describes a couple situations where Invalidate is the better choice.
Related
I have a problem with screen flickering. I read some other topics on this case, but there are solutions that didn't work for me, I think that's because I don't know what exactly causes the problem.
My screen is has a large number of controls, maybe this is what causes the problem. I'll try to describe it as best, as I can.
First of all, I am using WinForms.
I am making a video game, so the screen should be maximized all the time.
To allow stretching all the controls I am using TablePanels, one large that is docked to fill the whole form and a few smaller that also dock fill the large Table cells. In smaller cells of those tables, Buttons are docked fill.
To show the background drawn buttons, I made control buttons completely transparent. It needs to stay that way.
The screen flickers white at positions of TableLayoutPanels borders.
The screen flickers when a mouse enters the position of a Button, any Button, no matter where it is located.
For now, only one element changes actively during gameplay - a Label. When mouse enters the field of button, this label shows what this button does. For example if I enter the area of "Use" button, the label displays the word "USE".
I haven't tried that yet, but I must implement, that some images of button will change or become transparent, or lose transparency during game-play. Like there could be one image for closed cupboard, but when player opens it, another image of open cupboard appears. I think I know how to do it, all I want is to prevent flickering.
If you suggest using some code (and I expect it will be needed), please specify where I should put it.
It seems problem was solved.
I'll answer my question myself, in case someone else needs it.
The problem was caused by one of labels, although I can't guess why.
I am using a number of TableLayoutPanels, one of them fills the whole form. It has a number of rows, each of them is also a TableLayoutPanel, or just a Panel.
Flickering appeared when I tried to put a label inside main TableLayoutPanel by its own, and not in a sub panel. When I put a Panel inside main Table, and label inside it, the majority of flickering was gone.
To remove it completely, I used both recommendations just in case:
1) DoubleBuffering: Here (answer from Fabjan)
2) Article also recommended by Fabian
After that, only a few minor glitches remained. I did a few tests and it seems that the last glitches happened when mouse left the screen, then returned back inside. My game screen is maximized, so it took some time to check. To fix it, I used an easy command:
"Cursor.Clip = this.Bounds;" on FormLoad
I learned it from another question from this site: Here
Unfortunately, I didn't understand, why misplaced label was behind flickering, but since the problem was solved, I decided to write it here, in case someone else needs it.
Using VS2013, C#.NET 4.5, and WinForms. Migrating to WPF is not an option at this point.
The standard checkbox control handles 2-state and 3-state modes, but I need a 4-state checkbox. I can't find a 4-state checkbox library on the net anywhere, so I'm assuming I'll have to make one (if y'all know of one, that'd be great).
I have a set of four PNGs as draft images of the checkbox appearance, and I have played around with just painting those on a button and having the button_click event cycle through which image is displayed and update the data value. This doesn't seem to scale the image with the button well, though, and it feels kludgy to load static bitmaps instead of vector drawing the images so they're always to scale.
Is there a way to inherit from the checkbox control itself and add a fourth state?
If so, where do I go to override how the states are drawn? I need to do it "correctly" so that if the form is Scaled, the checkbox doesn't end up looking all bitmap-nasty.
I'm not even sure what keywords to use to search for how to do the actual drawing.
Background:
I'd generally consider this to be a nasty UI choice, but I'm making a program that saves, loads, and displays a "World of Darkness" character sheet of any arbitrary system, and the WoD games use a 4-state injury that's represented on the sheet by an empty box, a box with one slash across it, a box with an X across it, or a box with a 4-stroke asterix across it (optionally, a filled box).
For the moment I'm going with matching the original with high fidelity; later, as an option, I'll let the user switch to radio buttons to support my own preference.
This is my first real exploration of GUI programming beyond the basics, so I'm not sure quite how to proceed.
EDIT: I'm delving into a UserControl now, and my own draw methods. What fun. Found an MSDN tutorial on User-Drawn Controls, seems like a good starting place.
does anyone know how to do this? I presume it uses some sort of event handler but i wondered if anyone could set me on my path?
Also, how does one show that yellow textbox which sometimes appears when you hover over processional software and it gives some information about what to fill in the textfield, thats perferably how i wish to show the coordinates? I dont know the name of what its called.
In IE 8, if you hover over the name of a tab, it comes up.
Thank you in advance
Evets actually are not the way to go here. You want to show picture coordinates, pixel_accuracy. Mouse events are actually not accurate enough to do that. You will want to poll the mouses position on a timer and when you detect it hovering over your picture, tranlate the mouse position to pixel coordinates.
The yellow popup is called a ToolTip; search for C# ToolTips and I'm sure you'll find plenty. As for the hover, could you explain your intent better? It sounds like you may end up reinventing the wheel
If this is a webpage, Use javascript(/Jquery) to get the mouse co-ordinates and show them in a box. It would be much much easier, and dare I say it, really the only way to do it.
ASP.net isn't so much about client side interaction as you may be thinking along the lines of.
I've searched around for an alternative way of drawing selection indicators for visual objects (like selected edges, lines etc.) without the use of ControlPaint.DrawReversibleFrame and related XOR methods. The reasons are unwanted XOR-ing "artifacts", reversibility not applying to bitmaps, no control of the actual visual look and slowness.
On the other hand I want to avoid having to repaint the whole scene (map actually) if a user decides he wants to deselect an object or two, because the repaint could be quite expensive.
So the only alternative I can see is implementing some basic drawing logic directly on a Bitmap, but with storing the previous contents of the pixels before they change. Then (in theory) I would be able to reapply old contents of, say, an selected edge rectangle if the user chooses to deselect that edge.
My question is whether you think this is a good idea or do you see some other alternatives to my problem (within the GDI+)?
Thanks in advance
If the selection indicator is just drawn on the top of the unselected object, you can use two bitmaps, draw all the unselected objects on the background one and the selection indicators on the other, and paint them both on screen.
Else, you can do the same, except that you render the selected objects instead of just indicators.
Only store the rectangles "of interest" in an off screen buffer. And repaint when the focus is lost. . . Or if you can redraw just the portion as it appears normally based on in memory data you should be fine. Otherwise it seems that you have the gist of it.
I am programming winforms using c# and vb.net.
I love the arrows used in coderush.
for those who have not seen coderush arrows ,please see this image.
(source: aspnetpro.com)
http://www.aspnetpro.com/productreviews/2004/08/asp200408bn_p/asp200408bn_p_image002.jpg
I want to have something similar in my program.
only difference is i will be using it to highlight textboxes and buttons.
I only want the arrow , the text on the arrow is not important.
So maybe I need to make a general function like
DrawHighlightArrow(controlname)
and it will somehow manage to draw an arrow next to that control
Please suggest a nice geeky way to solve this problem in C# or Vb.net
Thank you
Anna
Override the OnPaint method on the Form, and use the DrawImage() method on the object from the PainteEventArgs.Graphics property to draw a bitmap of an arrow.
You could create a custom form with a transparent background, paint your arrow on it using GDI+ (using marxidad's technique above, or by just dropping a PictureBox on it and handling the Paint event).
Then just instantiate a new instance of the arrow form over the top of your existing "parent" form (you might want to set TopMost to true) and start a Timer to fade it out.
The only thing to be careful of there is...
cleaning up properly if you prematurely close the "parent" form, and...
passing through any click events to the "parent" form.
There is a really nice library called Locus Effects here. Go check it out, it does exactly what you want it to do.