I've been hunting about for some resources on this, and I can't find any, so I'll bring in here.
I want to make a window similar in style to the quick launch box which you see when you open the quick launch bar:
Example Window http://img63.imageshack.us/img63/6204/volcontrolstyleguide.png
Sadly, I can't find any resources on this; can you help me out?
It's quite simple. Create a new form, and set ControlBox, MaximizeBox, and MinimizeBox properties to false. Set the Title property to an empty string. This will effectively eliminate the the nonclient title bar area, giving you this:
The the interior section (like with "Customize") can be duplicated with a properly sized Panel and Link.
Assumptions :
this is a fixed size form, never re-sizable
you want this to work on XP as well as Vista (i.e., without using Vista specific techniques like 'Glass). I mention this because, after all, the System Tray does go back to the late paleolithic :)
Here's how :
create a Form the same size as your .png file
set the ControlBox, MaximizeBox, MinimizeBox properties to 'false
set FormBorderStyle to 'None
set the transparency key of the Form to some color, and set the background color of the Form to the same color : note use a color that does not occur in the .png file.
put a PictureBox on the Form, set its Dock property to 'Fill : set its Margin property #0 for all Margins : set its BackColor to 'Transparent : then, naturally, set the Image property of the PictureBox to your .png file.
NOTE :
If you have prepared your .png image so it is bounded by a transparent area so that it appears rounded : you can use that directly and skip over the whole step of actually making the Form a Rounded Rectangle by use of an API call to set the Region of the Form : this does mean your Form will have a standard rectangular bounding box. If you can live with this : this is a simpler solution. For how to set the Region : read on ...
see "How to make form rounded rectangle or round or triangle" here on SO for how to set the Region of the Form to a RoundedRect : this SO entry has several other links in it to code examples : the link mentioned by Zyphrax here uses the same basic technique.
experiment with the settings to the 'CreateRoundRect to get the rounded corner effect you want.
That sounds like you need Windows 7 API Code Pack, in which some API's are backward compatible with Vista. Since the specific version of Windows is not stated, I cannot say specifically..you could look here and here on CodeProject how this is accomplished.
Hope this helps,
Best regards,
Tom.
You can take an normal Form and modify it to look like your screenshot:
Set the FormBorderStyle property to None
Round the corners of your form: more info here
(Extend the glass if you like: more info here, only Vista or higher)
Set the background to White and add some controls to finish it off
Related
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.
The look I'm going for is like
where the sidebar is semi-transparent and the background can be seen through. However TransparencyKey only takes into account the pixels at the top, if there is another panel on top that means that together they do not fit the transparency key then it will be opaque.
I have the TransparencyKey set to Fuchsia and the grapefruit sidebar is on top and is changed to sidebar.BackColor = Color.FromArgb(128,255,255,255); on load.
As you see the TransparencyKey only works on the top.
I have also tried setting the transparency on the form with undesired results.
How would I go about making the sidebar translucent?
Solution v
You just can't do that in winforms. Period. It's an antiquated technology that doesn't support "real" transparency. Whenever you see the word "transparent", it really means your control will inherit the back color of its parent. It does not mean you can see things that are behind it.
You may be able to do it with WPF, though I'm not entirely sure.
As noted by #JeremyThompson WPF is absolutely fine at doing this.
Inside the window include WindowStyle="None" AllowsTransparency="True" Background="Transparent" and then use panels/canvases as normal.
When you set the size of a windows form, ie;
Form1.Size = new System.Drawing.Size(700, 500);
Does this include the border which windows puts around the form? Because I have added images (via pictureBoxes) which are 700x500 to my form, and they have been cut off by the border.
Also: When I say the border, I mean the default windows border which you can drag the edges of to resize it, as well as contain the red X, Minimize, and Maximize buttons.
That depends, you'll get a different size when you target .NET 4.5 for example. The border is always included but you don't really know how much of the border is included. An issue with the fat borders you get with Aero and the skinny ones you get in XP.
It is almost always the wrong thing to do. You always want to assign the ClientSize property instead. Important, it doesn't include the borders so you can be sure that controls still fit.
And hard-coding the size is always wrong as well. Your form will be rescaled, depending on the video adapter's dots-per-inch setting. The larger the DPI setting, the bigger the form needs to be to still fit its content. So the correct statement ought to resemble this:
this.ClientSize = new Size(PictureBox3.Right, PictureBox3.Bottom);
On the assumption that "PictureBox3" is the control in the far right-bottom corner that you want to keep visible. This statement needs to appear in the Load event handler to ensure that rescaling was done, it can't work in the constructor. One of the very few good reasons to use the Load event.
For a fast summary of the problem look at the picture at the bottom.
Hello,
I created a Form (named BaseForm) that serves as base for all my windows.
This base-Form contains (for the sake of simplicity) something like a "statusbar" (a usercontrol) at the bottom.
That statusbar is Locked so it can't be moved or resized in the designer.
It also has the it's anchor set to left,bottom,right so it always stays at the bottom and resizes horizontally.
Now when make another Form and change so it inherits MyProject.BaseForm instead of System.Windows.Forms.Form, the statusbar is there.
But now there is a problem with the statusbars position and size.
The statusbars standard location and size is wrong. VisualStudio takes the location and size from the BaseForm instead of applying the Anchor.
Also I can't (and don't want to!) move/resize the statusbar to fix the problem.
One obvious and working solution would be setting the statusbars Dock property to Bottom.
But I can't use that as a generic solution to my problem because I also have controls that should not be docked. (For example a button that should always stay at the bottom-right corner of the form)
You have a simple problem, the control is private so can't be messed with in the derived form. None of its properties are accessible, including Location and Size. Which freezes it solid in the wrong spot on your derived form. The layout engine can't move it either. And why it displays the lock icon.
Go back to the BaseForm, select the user control and change the Modifiers property from Private to Protected. Rebuild. Now you can move it on the derived form where it needs to go.
I think the best way to approach this is to use a TableLayoutPanel instead of explicit docking. Create a 2 row TableLayoutPanel in the parent form. Make the bottom row AutoSize and put the status bar into that. This way the derived forms are free to add content in the other row which represents the remainder of the control.
I am developing an application in C# and there is a requirement of the form of the main window in rounded rectangle or some times triangle type or round shape.
so, how can I achieve this kind of features in C# 2008
I think this is what you're looking for:
http://www.codersource.net/csharp_custom_window_forms.aspx
Also you can google for it, there are plenty examples.
Assuming this is on Windows Forms you can check these two articles on MSDN:
http://msdn.microsoft.com/en-us/library/aa289517(VS.71).aspx
http://msdn.microsoft.com/en-us/library/aa984331(VS.71).aspx
You basically have to do the following:
Remove the form border by setting its style to None
Set a background image that defines the shape of your form
Set the TransparencyKey of the form to the color that should be transparent
Look at the Region property of your form. You can create a new Region, set its shape using it's various Add... methods and then assign the region to your form's region property.