Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Non Rectangular Form

Non Rectangular Form

Scheduled Pinned Locked Moved C#
graphicscsharp
5 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sabry1905
    wrote on last edited by
    #1

    hi all I was making a non rectangular form in C# using a bitmap with a white background and set the transparency key property of the form to white and it works but when I color quality from the system properties to 32bit it didn't work is there any way to overcome this or is there a different method for drawing a non rectangular form using images thx for your interest

    P 1 Reply Last reply
    0
    • S Sabry1905

      hi all I was making a non rectangular form in C# using a bitmap with a white background and set the transparency key property of the form to white and it works but when I color quality from the system properties to 32bit it didn't work is there any way to overcome this or is there a different method for drawing a non rectangular form using images thx for your interest

      P Offline
      P Offline
      Pablo Hernandez Valdes
      wrote on last edited by
      #2

      The problem is that you may be using a 24bit image and it has some problems (I don't know why?) with 32bit color quality. Anyway there is a solution for this problem: 1) Load the image manually in the Load event(or wherever you want): Bitmap bg; bg=(Bitmap)Bitmap.FromFile(@"Your image.bmp"); bg.MakeTransparent(Color.White); Instead of this you can use an ImageList and don't forget to set the TransparentColor property 2) Draw the image in the Paint event: private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { e.Graphics.DrawImage(bg,0,0,this.Width,this.Height); //If you used an ImageList //e.Graphics.DrawImage(imageList1.Images[backgroundIndex],0,0,this.Width,this.Height); } Another approach to this could be using regions, but it is more complicated, if you want to learn more about this please let me know and I'll try to show you an example Pablo Hernandez Valdes

      S 1 Reply Last reply
      0
      • P Pablo Hernandez Valdes

        The problem is that you may be using a 24bit image and it has some problems (I don't know why?) with 32bit color quality. Anyway there is a solution for this problem: 1) Load the image manually in the Load event(or wherever you want): Bitmap bg; bg=(Bitmap)Bitmap.FromFile(@"Your image.bmp"); bg.MakeTransparent(Color.White); Instead of this you can use an ImageList and don't forget to set the TransparentColor property 2) Draw the image in the Paint event: private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { e.Graphics.DrawImage(bg,0,0,this.Width,this.Height); //If you used an ImageList //e.Graphics.DrawImage(imageList1.Images[backgroundIndex],0,0,this.Width,this.Height); } Another approach to this could be using regions, but it is more complicated, if you want to learn more about this please let me know and I'll try to show you an example Pablo Hernandez Valdes

        S Offline
        S Offline
        Sabry1905
        wrote on last edited by
        #3

        Hi Pablo Hernandez Many thx for your efforts to help me and others, i had used the code that u send to me and it didnt work see the code Bitmap bg; private void Form1_Load(object sender, System.EventArgs e) { bg=(Bitmap)Bitmap.FromFile(@"C:\Documents and Settings\sabry\Desktop\tt.bmp"); bg.MakeTransparent(Color.White); } private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { e.Graphics.DrawImage(bg,0,0,this.Width,this.Height); } and also i changed the transparency color to white i want to know why it didn't work in all color qualities and i want to know about the other methods again many thx :)

        P 1 Reply Last reply
        0
        • S Sabry1905

          Hi Pablo Hernandez Many thx for your efforts to help me and others, i had used the code that u send to me and it didnt work see the code Bitmap bg; private void Form1_Load(object sender, System.EventArgs e) { bg=(Bitmap)Bitmap.FromFile(@"C:\Documents and Settings\sabry\Desktop\tt.bmp"); bg.MakeTransparent(Color.White); } private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { e.Graphics.DrawImage(bg,0,0,this.Width,this.Height); } and also i changed the transparency color to white i want to know why it didn't work in all color qualities and i want to know about the other methods again many thx :)

          P Offline
          P Offline
          Pablo Hernandez Valdes
          wrote on last edited by
          #4

          Maybe it didn't work because the BackColor must be set to the color you want to make transparent, if not it does nothing at all. In my computer it works fine with this. If it still doesn't work please tell me and I'll try to send you my full code. If you want to do something like this using regions, for example, if you want a triangular window you can do System.Drawing.Drawing2D.GraphicsPath gp=new System.Drawing.Drawing2D.GraphicsPath(new Point[]{new Point(0,0),new Point(200,0),new Point(100,200)},new byte[]{(byte)PathPointType.Start,(byte)PathPointType.Line,(byte)PathPointType.Line}); this.Region=new Region(gp); Now you get a triangular window. You can intersect, join, complement different regions to obtain more complex shapes and even use non polygonal regions with bezier curves (PathPointType.Bezier). With a litte effort you can make a region that conform to your bitmap and use it for the form. Any problems please let me know. Pablo Hernandez Valdes

          S 1 Reply Last reply
          0
          • P Pablo Hernandez Valdes

            Maybe it didn't work because the BackColor must be set to the color you want to make transparent, if not it does nothing at all. In my computer it works fine with this. If it still doesn't work please tell me and I'll try to send you my full code. If you want to do something like this using regions, for example, if you want a triangular window you can do System.Drawing.Drawing2D.GraphicsPath gp=new System.Drawing.Drawing2D.GraphicsPath(new Point[]{new Point(0,0),new Point(200,0),new Point(100,200)},new byte[]{(byte)PathPointType.Start,(byte)PathPointType.Line,(byte)PathPointType.Line}); this.Region=new Region(gp); Now you get a triangular window. You can intersect, join, complement different regions to obtain more complex shapes and even use non polygonal regions with bezier curves (PathPointType.Bezier). With a litte effort you can make a region that conform to your bitmap and use it for the form. Any problems please let me know. Pablo Hernandez Valdes

            S Offline
            S Offline
            Sabry1905
            wrote on last edited by
            #5

            see this it works greet :) another good one like u helped me to do it public Form1() { InitializeComponent(); Bitmap Img = new System.Drawing.Bitmap(@"C:\myPic.bmp"); Img.MakeTransparent(Img.GetPixel(1,1)); this.BackgroundImage = Img; this.TransparencyKey = Img.GetPixel(1,1); } thx for ur interest :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups