且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使父MDI表单透明?

更新时间:2023-12-06 10:15:04

嗯,我注意到了.因此,我已经努力了.这是结果.

将父窗体的IsMdiContainer属性设置为false.然后,替换form_load事件处理程序,如下所示:

Well, I noticed that. hence, I''ve worked on it. and here is the result.

Set IsMdiContainer property of your parent form to value false. then , replace form_load event handler as following:

<br />
private void Form1_Load(object sender, EventArgs e)<br />
 {<br />
   this.TransparencyKey = Color.FromArgb(255, 220, 33, 55);<br />
   <br />
   MdiClient Client = new MdiClient();<br />
   <br />
   this.Controls.Add(Client);<br />
            <br />
   Form Child = new Form();<br />
   <br />
   Child.Size = new Size(100, 100);<br />
   Child.FormBorderStyle = FormBorderStyle.FixedDialog;<br />
   Child.StartPosition = FormStartPosition.CenterParent;<br />
   Child.MaximizeBox = false;<br />
   Child.MinimizeBox = false;<br />
   <br />
   Child.MdiParent = this;<br />
   this.pictureBox1.Controls.Add(Child);<br />
 <br />
   Child.Show();         <br />
 }<br />



此代码将保持透明,并添加mdiclient和子窗体.一切正常,正如您所看到的,childe表单可以在所有父表单区域上移动.因此,最后一个TODO正在寻找一种方法来防止其在透明区域上移动.
我也会尽快进行处理.

希望对您有所帮助.

--------------------
问候

H.Maadani



this code, will do transparency, and will add the mdiclient and child form. everything works fine, just, as you can see, childe form can be moved over all the parent form area. hence, the last TODO is finding a way to prevent it from being moved over transparented areas.
I''ll work on that too, as soon as possible.

hope this helps.

--------------------
Regards

H.Maadani


当然,有办法,我的朋友.

您总是可以通过以下几段代码来获得MdiClient的背景色:

Of course there is a way, my friend.

you can always get the back color of MdiClient by this little piece of code :

<br />
MessageBox.Show(string.Format("R = {0}, G = {1}, B = {2}",<br />
 Client.BackColor.R, Client.BackColor.G, Client.BackColor.B));<br />



如您所见,它是(171,171,171).
所以;



as you can see, it is (171,171,171).
So ;

<br />
this.TransparencyKey = Color.FromArgb(255, 171, 171, 171);<br />



将透明化表单本身.

P.S. 1:对可以帮助您的答案进行评分,使来此问题的人的生活更加轻松.当然选择答案作为解决方案会有所帮助. :)

P.S. 2:我已经将您的问题和答案发布为文章,供所有人使用.请访问
制作透明的MDI父表单 [



will transparent the form itself.

P.S. 1 : rate the answers which help you, it makes life easier for people who come visit this question. and of course choosin an answer as solution wil help so. :)

P.S. 2 : I''ve published your question and the answers as an article for everyone to use. visit it at
Making a transparent MDI parent form[^]

------------------
Regards

H.Maadani


您可以使用区域创建非矩形窗口.
这是一篇演示此内容的文章-
为表单和按钮创建位图区域 [
You can create non-rectangular windows using regions.
Here an article that demonstrates this -
Creating Bitmap Regions for Forms and Buttons[^]