Click here to Skip to main content
13,347,168 members (56,621 online)
Click here to Skip to main content
Add your own
alternative version


22 bookmarked
Posted 13 Apr 2009

UI Ideas

, 13 Apr 2009
Rate this:
Please Sign up or sign in to vote.
Rough Ideas about UI Designing


This is a simple article in which some rough ideas about UI that you might have thought about are presented. 

In this article, we will see how to:

  • Change the mouse cursor inside the form
  • Change the appearance of the form by re-drawing it
  • Change the appearance of the form using its TransparencyKey property
  • Change the opacity of the form and its drawing size
  • Move the form by dragging any part of it 


I was wondering how different shapes of Windows Forms can be designed and that's where I found the information to write this article.  

Using the Code

Use the following part to change to mouse cursor. You need to pass the bitmap object to the ChangeCursor function. I would usually pass an embedded resource stream.

private void ChangeCursor(Bitmap b)
    Graphics g = Graphics.FromImage(b);
    IntPtr ptr = b.GetHicon();
    Cursor c = new Cursor(ptr);
    this.Cursor = c;

The following would first hide your default form borders, draw a simple graphic object and set it to the current form. A simple circle in this case.

this.FormBorderStyle = FormBorderStyle.None;
gP = new GraphicsPath();
gP.AddEllipse(0, 0, this.Width, this.Height);
this.Region = new Region(gP); 

To change the ellipse size and re-apply it back to the form, we use the following:

float i = ((TrackBar)sender).Value;
gP = new GraphicsPath();
this.Region = new Region(gP); 

Opacity adjustments would simply take place by changing the Opacity property associated with the control.

this.Opacity = ((TrackBar)sender).Value / 100f; 

Our Evening Star

To draw other shapes, you would usually use the other methods listed under the GraphicsPath object like the AddPolygon method which allows you to freely define the points of your random polygon "a good practice would have been drawing the star in this article, but it's almost 3 in the morning and I'm a bit lazy to do that". 


In this example, I had a simple star auto shape drawn in Microsoft Word, copied it to Adobe PhotoShop to set the outside part of the image to transparent. In the application, we do the following:

  • Create a PictureBox control
  • Give it an Image (Our little art piece from Microsoft Word)
  • Add our PictureBox to the form and dock it to fill the whole area
  • Set the TransparancyKey to whatever and change the form BackColor accordingly:
if (((RadioButton)sender).Checked)
    PictureBox pb = new PictureBox();
    pb.Image = new Bitmap(Properties.Resources.pStar);
    pb.Dock = DockStyle.Fill;

    this.TransparencyKey = Color.Red;
    this.BackColor = Color.Red;

Last but not least, we have to give our form a different handle to allow us to move it. The little part proceeding the constructor in our example defines the following region to be used later in the associated mouse event:

#region To move form with mouse
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;

public static extern int SendMessage(IntPtr hWnd,
                         int Msg, int wParam, int lParam);
public static extern bool ReleaseCapture();

And in the MouseMove event, we say:

if (e.Button == MouseButtons.Left)
      SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);

Points of Interest 

You may have noticed how the star shape is clipped from the bottom, this is because the path object is still applied to the form and the star location starts at the beginning of the ellipse but ends beyond its invisible part which makes us think about the combination of shapes we can create! Use your imagination!

You have to remark that a VDU with a poor or inappropriate hardware drivers would completely omit the transparency and the opacity effects to probably give you a solid black color.


Special thanks to FreewareFire for moving our form of which this code part is captured from the article: 


  • 13th April, 2009: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Retired QSoft
Yemen Yemen
Biography?! I'm not dead yet!

You may also be interested in...

Comments and Discussions

GeneralA good starting point Pin
SohjSolwin21-Apr-09 7:34
memberSohjSolwin21-Apr-09 7:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 13 Apr 2009
Article Copyright 2009 by Muammar©
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid