I wonder if it’s possible to customize my C# application (winforms) to get a better design, I made a PSD (photoshop document) so I can generate png jpeg… pictures if I need them.
Example of a form like the one I want :
I wonder if it’s possible to customize my C# application (winforms) to get a better design, I made a PSD (photoshop document) so I can generate png jpeg… pictures if I need them.
Example of a form like the one I want :
2
Answers
If you need a lot of special graphics effects learning WPF will indeed be a sound investement.
If all you want is that login screen, it is trivial in Winforms and doesn’t take any horrible hacks as you’ve been told..
These seven lines are all it takes for a form to be transparent. I copied them from the Designer code; you can simply set the 7 Properties in the property grid.
Now add a panel, dock it to the bottom and give it the right color; add a picturebox and your other controls and you are set.
To create the two input groups you also need just a few regular controls and only a few simple lines of code:
You place one Panel,
BorderStyle = FixedSingle;
and add a Label and a TextBox to it. The Label hasAutoSize = False;
and bothImageAlign
andTextAlign
are set toMiddleLeft
. You assign an image to the Label’sImage
and prefix theText
with enough blanks to not overlap. Obviously you should define aPasswordChar
for the 2nd TextBox. Now all you need is to script theEnter
andLeave
events to change the BackColor of the respective Panels between, saySystemColors.Control
andSystemColors.MenuHighlight
. Size the Labels to almost fill the Panels and you are done. Less code than the WPF version, I’d bet.If you need such input an controls again and again, simply create Usercontrols for each type you need!
Here is an example of the limits you will hit: Wouldn’t it be nice to add a dropshadow effect to the image? It is doable in Winforms. But it would involve painting that effect; this would take at least 15 or 20 lines of involved code instead of simply turning the effect on with (estimated) 1-3 simple lines.
Do you need any nice hover effects? Not easy, to say the least..
These limits will be all over the place, so it really depends on how fancy your requirements will get.
Maybe you should use this example as a starter to compare the two techniques and to warm you up to WPF?
Indeed as it was pointed out in the comments, it is easy to use WPF (indows Presentation Foundation) to achieve that result, but if you really need that it must be made in windows forms I can help you with that…
ControlBox and Border
It seens that your form does not have a control box (minimize, maximize and close buttons)
to achieve that you can set
I’m not sure if that galaxy behind your form is part of the application so i’ll be considering that it is not
To achieve that irregular shape of the form we have to do a workaround here
Irregular Shape of the Form
we are going to set a Color to TransparentKey, so everything in the form in that specific color will be transparent, like it does not exists (if you click in that part it will go into de desktop or whatever application you have behind in your form)
So let’s use a specific color which we will probably dont use in the form
So in order to make that white part we are going to use an Panel and a PictureBox outsite of the Panel trying to copy the shape of your image
Stylized Inputs
To make it easier and reusable I’m going to make a userControl in this one
the usercontrol will have
Now we have to make some properties in our UserControl to make it work without work in other controls
First in the SizeChanged event of the HighLightPanel we will make the BackColorPanel be exacly two points smaller in every direction and its position to 1;1 so we can see the HighLightPanel
Now we will create two propertys to handle the Highlight Color
And in the Enter and Leave Property of our TextBox we are going to change the HighlightPanel
So now every time the user enter the Input it will appear that the Input has an Border in the specified Color
Now to enhance its usability to developers we will make some wrappers in its controls to be easier change property of child controls in the editor
In the InputImage set the picture you want for the User and the Key
Insert the two controls in the position you like
Position of the Form
if you want your form to be moveable without the border you will have to use this snippet, it is more easy in WPF