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
  1. Home
  2. General Programming
  3. C#
  4. UserControl

UserControl

Scheduled Pinned Locked Moved C#
comgraphicstoolshelpquestion
1 Posts 1 Posters 0 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.
  • F Offline
    F Offline
    fjlv2005
    wrote on last edited by
    #1

    Good day, I have a form, i've set the BackColor to Black and also the transparency to Black. then on the form a UserControl which has a gradient backcolor. Inside the UserControl i've put two basic controls(Label1 and Button1). I've set the BackColor of Label1 and Button1 to Transparent. What happened is that the Label1 and Button1 transparency goes through the form itself. See Link Below: http://www.geocities.com/fritzjeran/Sample.JPG What I really wanted is that when i set the BackColor of the Label1 and Button1 to transparent, I goes through ONLY up to the UserControl (i.e what should appear is the gradient color of usercontrol on the area that is overlapped by label1 and Button1). How should I fix this?:(( Here is the code of my Usercontrol:

    public partial class BaseControl : UserControl
    {
        public BaseControl()
        {
            InitializeComponent();
            SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.EnableNotifyMessage, true);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            if (this.BackgroundImage == null)
            {
                Rectangle rect = new Rectangle(0, 0, Width, Height);
                LinearGradientBrush b = new LinearGradientBrush(rect, Color.White, Color.Blue, 90);
                GraphicsPath path = GraphicsPathUtility.GetRoundRectPath(rect, 10);
                e.Graphics.FillPath(b, path);
            }
            base.OnPaint(e);
         }
    }
    
    #region Utility Classes
    public class GraphicsPathUtility
    {
        private GraphicsPathUtility()
        {
        }
        public static GraphicsPath GetRoundRectPath(RectangleF rect, float radius)
        {
            return GetRoundRectPath(rect.X, rect.Y, rect.Width, rect.Height, radius);
        }
        public static GraphicsPath GetRoundRectPath(float X, float Y, float width, float height, float radius)
        {
            GraphicsPath gp = new GraphicsPath();
            gp.AddLine(X + radius, Y, X + width - (radius \* 2), Y); //
            gp.AddArc(X + width - (radius \* 2), Y, radius \* 2, radius \* 2, 270, 90);//
            gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius \* 2));
            gp.AddArc(X + width - (radius \* 2), Y + height - (radius \* 2), radius \* 2, radius \* 2, 0, 90);
            gp.AddLine
    
    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