Solved

.Net Transparent Form Back Ground

Posted on 2010-09-21
14
344 Views
Last Modified: 2012-05-10
I want a form background as this :

http://www.launchy.net/images/screenshot_sheep.jpg

how should i do it
0
Comment
Question by:3XLcom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 2
14 Comments
 
LVL 19

Expert Comment

by:Shahan Ayyub
ID: 33727127
Hi!

One way as I see is that you can use two forms form1, form2.

form1 has opacity is less, like 20% etc and
form2 has opacity 100%

form1 has ShowInTaskbar property =false.
0
 

Author Comment

by:3XLcom
ID: 33729133
ok what about corner on the forms
0
 
LVL 19

Expert Comment

by:Shahan Ayyub
ID: 33733321
You can use Form_Paint event to redraw the form by making Polygon(Graphics.DrawPolygon). This will help to reshape the form.
0
Containers and Docker for Everyone

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

 
LVL 8

Expert Comment

by:mac-will
ID: 33737033
The partial class below give the form in this screenshot.

You would need to add quite a bit of mouse/focus handling code...

MAC
   public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        internal static GraphicsPath CreateRoundedRectanglePath(Rectangle rect, int cornerRadius)
        {

            GraphicsPath roundedRect = new GraphicsPath();
            roundedRect.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90);
            roundedRect.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y);
            roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90);
            roundedRect.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2);

            roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90);

            roundedRect.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom);
            roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90);
            roundedRect.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2);
            roundedRect.CloseFigure();
            return roundedRect;

        }


        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle lRect = new Rectangle(new Point(0,0), this.Bounds.Size);
            lRect.Inflate(-1, -1);

            using (GraphicsPath path = CreateRoundedRectanglePath(lRect, 12))
            {
                e.Graphics.DrawPath(Pens.White, path);

                e.Graphics.FillPath(new LinearGradientBrush(lRect,
                    Color.FromArgb(100, Color.White), 
                    Color.FromArgb(100, Color.WhiteSmoke),  
                    LinearGradientMode.Vertical), path);
            }

            lRect.Inflate(-18, -18);
            using (GraphicsPath path = CreateRoundedRectanglePath(lRect, 12))
            {
                e.Graphics.DrawPath(Pens.White, path);

                e.Graphics.FillPath(new LinearGradientBrush(lRect,
                    Color.DarkGray,
                    Color.Black,
                    LinearGradientMode.Vertical), path);
            }

            e.Graphics.DrawString("Hello test 1,2,3...", this.Font, Brushes.WhiteSmoke, new PointF(50, 50));
        }
        protected override void OnActivated(EventArgs e)
        {
            base.OnActivated(e);
            this.Invalidate();
        }

        /// <summary>
        /// Gets the creation parameters.
        /// </summary>
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x20;
                return cp;
            }
        }

        /// <summary>
        /// Paints the background.
        /// </summary>
        /// <param name="e">E.</param>
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            // do nothing
        }

        protected void InvalidateEx()
        {

            if (Parent == null)
                return;

            Rectangle rc = new Rectangle(this.Location, this.Size);

            Parent.Invalidate(rc, true);
        }
    }

Open in new window

Untitled.jpg
0
 

Author Comment

by:3XLcom
ID: 33740663
CreateRoundedRectanglePath()

how should i use this function i don't understand i am sorry
0
 
LVL 8

Expert Comment

by:mac-will
ID: 33743507
See how I used it in the example OnPaint method above.
0
 

Author Comment

by:3XLcom
ID: 33745177
i checked it already, i could not find what to write to :
Rectangle rect, int cornerRadius
0
 
LVL 8

Expert Comment

by:mac-will
ID: 33745966
I'm not sure what you mean.  What do you mean when you say "could not find what to write"?

Basically I provided a complete class that produces the look of a form much like your example.

The function CreateRoundedRectanglePath() takes as parameters a rectangle and a corner radius and returns a graphics path of a rounded rectangle.


Do you understand what is going on here?  We are custom painting the form.
0
 

Author Comment

by:3XLcom
ID: 33746176
yes i understand but i do not understand how to call CreateRoundedRectanglePath() this function for ex.


CreateRoundedRectanglePath(?????, 12);

sth like this but what will i put the ????? part
0
 
LVL 8

Accepted Solution

by:
mac-will earned 500 total points
ID: 33747322
This parameters takes a Rectangle Object.

For example a Form has a Bounds Rectangle.

try making a new rectangle

Rectangle myRect =  new Rectangle(0, 0, 100, 300);
0
 

Author Closing Comment

by:3XLcom
ID: 33747444
Thanks Perfect Job
0
 

Author Comment

by:3XLcom
ID: 33747605
I want to add one thing if sth. come behind to the form then go out the shadow getting worst why ?
Untitled.png
0
 
LVL 8

Expert Comment

by:mac-will
ID: 33754590
because it isn't repainting the desktop properly so it is repainting over itself...
0
 

Author Comment

by:3XLcom
ID: 33755677
do you have any advice for solution?
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question