Ok, I have googled, but maybe I put my search in weirdly. :/
I have a VB.NET WinForms application. I have the anchor properties set for all the controls so that it will resize all the controls to look decent when the form is maximized. (Haven't gotten around to manual resizing yet however).
Anyway, the problem:
I go to set the same properties for a button (testing with a single button for now) on the main GUI form/picture. When I go to run the program via F5, it looks decent. But when I maximize the form, the entire button covers up more than it should.
I've taken screenshots of the form so you can see a visual of what I'm talking about. :/
Before: http://zack.scudstorm.com/before.png
After: http://zack.scudstorm.com/after.png
What other propert(y|ies) do I need to set for the buttons to show up correctly? :/ (The buttons go over the boxes that say, for example, "1-1", "2-3", etc.
Thanks,
-Zack
Seems like you have anchored top-left and bottom-right when what you want is just top-left.
Edit: If it's just an image that does not change when the winform changes, then don't anchor your buttons at all. Just put them where they go. If you are scaling the image, then I would either detect the clicks on the image and do the scaling math or do the scaling math and set my buttons in code in the Form.OnResize event.
As it appears that your goal is just to be able to handle clicks on the "computers"...
One option that can be useful for this sort of task is to create an "overlay" bitmap (not displayed, but which is the exact same size as your source bitmap) which uses different colors to represent all the clickable regions. (e.g. (R=0,G=0,B=0) for computer 0, (0,0,1) for computer 1, etc)
You could even generate this bitmap somewhat automatically without too much trouble (If you have a mode where you can click the top left and then bottom right corners of the image to define a new region)
When the mouse is clicked, you can check the pixel at the scaled coordinates of the mouse position in the overlay and determine what their click corresponds to. This can be a lot easier than creating loads of controls, and makes it a lot easier to have clickable regions that aren't rectangular.
Related
I have a Winform I want to resize. Not after launching; I want to resize it in the designer by dragging the edges.
I am aware that I can change the size manually in the form properties. This is not what I want to do. I want to quickly size the default size of the form with my mouse.
The problem appears to be that I cannot grab the edges of the form for some reason. I repeat, this is NOT DURING RUNTIME. It is not that I have disabled/enabled Autosize/Resizing.
It's almost like the edge grabs are a single pixel wide and I just can't hit it. I don't know. I've looked for accessibility settings. The last thing I want to do is reinstall MSVS. It's just maddening.
I've attached a photo. The little boxes on the bottom, right, and bottom-right corner are my targets.
you can try to click the form title before resizing. I think you may have a panel (or any container control) which is full docked in the form, that's why when you click the form body, you selected the panel instead of the form.
Another issue that I encountered was the windows font size was set to 120% (or more), so go to windows display setting and set the font size to 100%.
I'm using Windows 10, Visual Studio 2017 and writing a C# Windows Form Application.
I have a windows form application that I am writing (partly in an attempt to get better at writing such things). I have designed my form nicely, with everything spaced and sized properly, but when I press F5 to start the form to debug it, I find that it loads at about 75% the size of the one I see in the designer.
This resizing seems a bit hit and miss, with buttons that were previously aligned no longer being so, and text no longer fitting in its spaces (see pic - the top part shows the designer and the bottom shows the actual form being run).
I would like to have the designer accurately reflect the final look of the form - does anyone know what is going on or how to avoid the problem? Everything I have looked at on the web talks about choosing to resize the form, not this enforced resize!
Have you changed the whole form font size? By default WinForms designer set
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
try changing the AutoScaleMode and see what happens.
I've experienced similar WinForms designer issues when the default Font (in the form property) size is not 8,25pt. I dont't know why but seems related to desktop and/or screen configuration. Not sure but some weird behaviours could be bugs (WinForms is now quite old...).
AutoScaleMode.Font means that form scaling is based on font size. So trying changing different font settings can solve the problem.
hope this help
When designing the form, the form automatically sets the anchor points to Top Left. You will have to set the anchor points to your form.
The anchor style works like this. On a control if you set anchor points to:
Top/Right then the control stays in the Top Right.
Top/Left then the control stays in the Top Left. Bottom/Right then the control stays in bottom right. Bottom/Left then the control stays in bottom left.
Top then it stays at the top.
Bottom then it stays in the bottom.
Left then it stays in the Left.
Right then it stays in the right.
Top/bottom stretches top to bottom.
Left/Right stretches left to right.
Now when you anchor a control to any of those combinations they will stay in that location when form is maximized. Controls can anchor to each other as well.
I hope this helps.
Also here is a tutorial I did on this.:
https://youtu.be/wlZ6pt79v1E
accurately reflect the final look of the form
Your form's appearance is mostly decided by the end user. Font, size, colour, scale, contrast... all these things are under the users control, not yours.
Consider using split panels, and maybe some flow panels. Get used to 'randomly sizing' the form when you think you've finished designing, to see how it reacts to being the 'wrong size'. Someone will find a way to shrink or grow your form, and handling that gracefully is easier than enforcing a view.
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.
Hello,
Above is the program I am writing. On the right panel is basically two custom controls (the blue rectangle area) I created and just added them as controls to the background panel control when this winform program loads.
I used MS paint to draw out the pop up balloon that I want to see when my mouse enter this control's area. I want to do the following:
1. If mouse enter the control area, the yellow area balloon pop up and populate with the information of that specific control
2. If mouse move out of the control area, the pop up balloon disappear.
Can this be done with Winform application? I looked around and found out about Tooltip class but so far from researching I don't know if it does what I want to do.
I could be wrong but googling around gave me the impress that Tooltip offers very little in term of style. Ideally I want to make this pop up balloon into almost like a border-less pop up window where I can put image , font ect.....at will. Also Tooltip works if you hover over a button or specific field whereas I want the entire control area.
Can this be done? I appreciate if you can point me to any work around if there is one.
I wrote a comment, but I figure I'll expand it into a full answer. This is assuming you want a new control, which isn't a tooltip, for maximum customizability. I did something similar to this for work recently, to act as a non-modal info popup that disappears when clicked.
Creating a Custom Popup Form
What you want is essentially a floating popup that appears over your form, which means you'll want to define a new Form object, rather than a UserControl, as it won't actually be embedded within your other form.
Give it a multiline, non-editable textbox that you can fill with the information you want to populate, then simply call a new instance of the form on your Mouse_Enter event. Close it upon Mouse_Leave.
Adjusting The Style
You'll have to play with it a bit to get it to actually act like a popup and not just a window. I'd recommend setting it to a non-modal popup, and removing the border. You can write a function to automatically size it to its contents. I don't imagine you'll want the user manually resizing it.
Some other things to look into would be overriding the CreateParams property that comes with the basic Form object. You can force DropShadows and TopMost forms without making the form modal. Overriding ShowWithoutActivation to always return true will prevent the form from stealing focus when it pops up.
I'm not sure if you can pull off rounded edges like you have in your mockup. Perhaps you can pull it off with some wizardry in the OnPaint() function, but I couldn't tell you how to do it.
It might be a bit of a pain for fiddling around with, but you can get some good functionality and appearance out of it. If you think you can pull it off acceptably with the ToolTip class, go for it. It took me about a week to get my notifications where I wanted them (though I added several features that you probably don't need to worry about).
Examples
Some keywords to look up in related searches would be Toast Notification and Non-Modal Popup. This might be some use:
http://www.codeproject.com/Articles/442983/Android-Style-Toast-Notification-for-NET
Since you already have implemented custom user controls you might want to try it again. Make a control that is that style and color, changes it's size based on it's text. You can feed it information (such as the text to display) from your existing user control object. You can also have the mouse enter/leave code reside in your first user control.
If you're not sure how to make a rectangle with round corners you can either make it on the fly using a graphics object (which will turn into a bitmap on the screen) or make it how you want it to look in GIMP (or photoshop if you have it) then use that image as the background on your user control. Make the default background transparent (so your voids above the round corners are not grey). If you make a pre loaded image you'll need to be aware you will only be able to scale it equally in Y and X directions. unequal scaling will make it look distorted.
Can you use the Mouse_Enter event on the control?
I´m using WinForms. I want to make a little class, which modifys controls to show it´s working.
I want to draw an overlay over for example a button. It should be a half-transparent gray.
After that i want to draw a ProgressBar on over it (in the center). Similar to This, except using a progress bar.
How can i realize this? I don´t want to set the position of the progressbar, just drawing it on the other one.
How could i do this?
Thanks :)
I have done something similar before.
You need to use Button.DrawToBitmap(Bitmap, Rectangle) to get the image of the button. Then make the Bitmap grayscale (there are multiple algorithms available for this; I have used the last one successfully although probably not originally from this site).
Now, I did this with an entire form instead of a button, but I disabled the form, and then covered the entire form with an image of itself, altered and then covered it with the progress bar (itself in a panel with other controls).
You could just as easily disable the button, cover it with a panel containing the image and the progress bar on top of it.