Thursday 15 January 2015

c# - How to make a transparent form to be painted -


Before asking a question, I am sorry that I am not a native speaker on English hence my sentence can be strange. My question is below

I am creating a project to attract as a transparent windows. I use C # to create this project. The code I created is below.

  Public Notification () {InitializeComponent (); SetStyle (ControlStyles.SupportsTransparentBackColor, true); This.BackColor = Color.Transparent; } Public Zero PaintOnform () {System.Drawing.Graphics g = this.CreateGraphics (); Pen pen = new pen (system, drawing collar black, 5); G. Drone (pen, 0, 0, 50, 50); Console.WriteLine ("write!"); }  

And I also tried to do it.

  Public Notification () {InitializeComponent (); This.BackColor = Color.Blue; Transparency = Color Blue; } Public Zero PaintOnform () {System.Drawing.Graphics g = this.CreateGraphics (); Pen pen = new pen (system, drawing collar black, 5); G. Drone (pen, 0, 0, 50, 50); Console.WriteLine ("write!"); }  

When I try to make the background opaque, it pulls the line correctly, however, when I try to make the background transparent, no line shows up.

How can a transparent windows be painted?

If the solution by other means is made with C # (eg WPF), can you please tell me?

Transparent to create a WPF window, there are some properties that you need to set up. Background = "Transparent", Allow Transparency = "True" and Window Style = "None":

  & lt; Window x: orbit = "wpfApplication8.MainWindow" xmlns = "http://schemas.microsoft.com/comfx / 2006 / xaml / presentation" xmlns: x = "http://schemas.microsoft.com/winfx/2006/ Xaml "title =" main window "height =" 350 "width =" 525 "background =" transparent "allows Transparency =" True "WindowStyle =" None "& gt; & Lt; Border borderbrush = "white" border-left = "2" & gt; & Lt; Canvas X: name = "canvas" /> & Lt; / Border & gt;  

Regarding drawing on the window, I recommend drawing on a canvas.
A background brush will not be defined on a canvas, unless you define one, so you do not need to do anything there.

Believing that you want to do it in code (you can do this in XML, depending on the case of your use):

P>
  public Manvindo () {InitializeComponent (); Var line = new line {stroke = new solid collarbrush (black color), strokecthenes = 5, x1 = 0, y1 = 0, x2 = 50, y2 = 50}; This.Canvas.Children.Add (line); }  

No comments:

Post a Comment