子窗口不在父窗口显示

问题描述

以下是子窗口的实现代码,为了模拟安卓的Toas提示t效果//CSToast.csusingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Diagnostics;usingSystem.Drawing;usingSystem.Drawing.Drawing2D;usingSystem.Text;usingSystem.Windows.Forms;namespaceCSToastTip{publicpartialclassCSToast:Form{privateTimertm=newTimer();privateFormfrmParent;privateLabellabel1;privatestringstrMsg;privateconstintdefHeight=22;privateconstintroundSize=10;publicColorclrBack;publicColorclrText;privatevoidInitializeComponent(Formfrm){frmParent=frm;this.label1=newSystem.Windows.Forms.Label();this.SuspendLayout();this.label1.AutoSize=true;this.label1.Location=newSystem.Drawing.Point(130,109);this.label1.Name="label1";this.label1.Size=newSystem.Drawing.Size(41,12);this.label1.TabIndex=0;this.label1.Text="label1";this.ClientSize=newSystem.Drawing.Size(284,262);this.Controls.Add(this.label1);this.FormBorderStyle=System.Windows.Forms.FormBorderStyle.None;this.Name="CSToast";this.Load+=CSToast_Load;this.ResumeLayout(false);this.PerformLayout();if(null!=frmParent){this.TopMost=true;this.TopLevel=false;frmParent.Controls.Add(this);this.BringToFront();}}publicCSToast(Formfrm){InitializeComponent(frm);DefColor();strMsg="thisisatoastmessage";tm.Interval=1000;tm.Start();tm.Tick+=tm_Tick;}publicCSToast(stringmsg,Formfrm){InitializeComponent(frm);DefColor();strMsg=msg;tm.Interval=1000;tm.Start();tm.Tick+=tm_Tick;}publicCSToast(intinterval,stringmsg,Formfrm){InitializeComponent(frm);DefColor();strMsg=msg;tm.Interval=interval;tm.Start();tm.Tick+=tm_Tick;}publicvoidDefColor(){this.clrText=Color.White;this.clrBack=Color.Black;}voidtm_Tick(objectsender,EventArgse){this.Close();}privatevoidSetWindowRegion(){System.Drawing.Drawing2D.GraphicsPathFormPath;FormPath=newSystem.Drawing.Drawing2D.GraphicsPath();Rectanglerect=newRectangle(0,defHeight,this.Width,this.Height-defHeight);FormPath=GetRoundedRectPath(rect,roundSize);this.Region=newRegion(FormPath);}privateGraphicsPathGetRoundedRectPath(Rectanglerect,intradius){intdiameter=radius;RectanglearcRect=newRectangle(rect.Location,newSize(diameter,diameter));GraphicsPathpath=newGraphicsPath();//左上角path.AddArc(arcRect,180,90);//右上角arcRect.X=rect.Right-diameter;path.AddArc(arcRect,270,90);//右下角arcRect.Y=rect.Bottom-diameter;path.AddArc(arcRect,0,90);//左下角arcRect.X=rect.Left;path.AddArc(arcRect,90,90);path.CloseFigure();returnpath;}protectedoverridevoidOnResize(System.EventArgse){this.Region=null;SetWindowRegion();}privatevoidCSToast_Load(objectsender,EventArgse){using(Graphicsgraphics=CreateGraphics()){Fontf=newFont("楷体",14F,System.Drawing.FontStyle.Regular);Sizesif=TextRenderer.MeasureText(graphics,strMsg,f,newSize(0,0),TextFormatFlags.NoPadding);//MessageBox.Show(sif.Width.ToString());this.Size=newSize(sif.Width+defHeight*2,sif.Height+defHeight*2);label1.Text=strMsg;label1.Font=f;label1.Location=newPoint(defHeight,defHeight*3/2);if(null!=clrBack){this.BackColor=clrBack;}if(null!=clrText){label1.ForeColor=clrText;}}if(null!=frmParent){this.Location=newPoint(frmParent.Location.X+frmParent.Width/2-this.Width/2,frmParent.Location.Y+frmParent.Height/2-this.Height/2);}else{this.CenterToScreen();}BringToFront();}}}

然后在另一个窗口中调用,但是窗口不显示privatevoidbutton1_Click(objectsender,EventArgse){CSToastts=newCSToast(1000,"testmessage",this);ts.Show();}

解决方案

解决方案二:
自己发现了问题。。。。。if(null!=frmParent){this.Location=newPoint(frmParent.Location.X+frmParent.Width/2-this.Width/2,frmParent.Location.Y+frmParent.Height/2-this.Height/2);}

这一行,Location的定位是相对容器的,所以应该改成if(null!=frmParent){this.Location=newPoint(frmParent.Width/2-this.Width/2,frmParent.Height/2-this.Height/2);}

时间: 2024-08-31 01:29:48

子窗口不在父窗口显示的相关文章

ie 8-js子窗口关闭刷新父窗口

问题描述 js子窗口关闭刷新父窗口 使用window.showModalDialog("uploadFile.jsp",null,"dialogWidth=400px;dialogHeight=250px"); 方式弹出的一个子窗口, 我需要用子窗口控制刷新父窗口然后关闭子窗口, window.parent.dialogArguments.document.execCommand('Refresh'); window.close(); ie8下执行不成功 解决方案

分析一下网页子窗口和网页父窗口的交互

父窗口|交互|网页|子窗口 1.父窗口传递信息给子窗口 看代码实例: <script language=javascript>function outPut()...{ //获取父窗口的文本信息赋值给text var text = document.abc.text.value; //打开子窗口,并且把操作句柄赋值给win变量,以下所有操作都是针对win对象的 var win = window.open("","mywin", "menubar

jtable-JAVA JTable 中触发JComboBox导致子窗口会到父窗口后面

问题描述 JAVA JTable 中触发JComboBox导致子窗口会到父窗口后面 各位大神: 本人在JTable中添加了JComboBox控件,通过一个按钮去触发子界面,如果在JTable中触发了JComboBox控件就会导致需要弹出的子窗口不能在最前面一直在父窗口的后面.如果没有去触发JComboBox控件,则弹出的子窗口会在最前面. 代码如下: JComboBox控件在JTable中添加方式: JComboBox isJTCombox = new JComboBox() isJTCombo

不关闭子窗口不能操作父窗口该怎么做

问题描述 在父窗口中有个按钮 调用js方法弹出一个窗口想要实现:不关闭子窗口 不能操作父窗口该怎么做请各位指教 问题补充:7454103 写道 解决方案 这个也一样啊! 你平时 父子窗口 咋传值这个也可以的! 如果 父子窗口 传值不是很熟悉 可以百度下 一堆资料!解决方案二:模态窗口 本身就是这样!/*打开一个模态窗口*/function openModalWindow(url, actionName, width, height) {window.showModalDialog(url, ac

WPF Frame做导航的时候 在子页面怎么获取父窗口的控件

问题描述 RTWPFFrame做导航的时候在子页面怎么获取父窗口的控件?比如<FrameDockPanel.Dock="Top"x:Name="MainFrame"NavigationUIVisibility="Hidden"Source="Welcome.xaml"/> 在Welcome.xaml页面里面怎么获取父窗口的控件并且定义事件? 解决方案 解决方案二:自己顶!!!!!解决方案三:没人来?自己顶!解决方案

lhgdialog插件问题,弹出子窗口,并且点击子窗口的按钮时,关闭子窗口并且刷新父窗口!

问题描述 父窗口代码:<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="Parent.aspx.cs"Inherits="WebApplication1.Test.关闭子窗口并且刷新父窗口.Parent"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""h

c++-小弟请教在MFC中子窗口如何获取父窗口的句柄啊

问题描述 小弟请教在MFC中子窗口如何获取父窗口的句柄啊 比如我有个父类的Dialog类为A,还有一个子类的Dialog类为B,然后在A类的头文件中包含了B的头文件,然后在A类中生命一个B类的成员变量,类似下面那样,然后我通过一个button调用DoModal();B类的STYLE改为CHILD了: 然后我希望在子窗口中处理一些数据,然后传给父窗口:比如A中有个IDC_text1 有个IDD_BUTTON1,B中有个IDC_text2,有个IDD_BUTTON2: 我就希望在B中的IDC_tex

在父窗口上弹出子窗口,子窗口关闭刷新父窗口

问题描述 一.父窗口上:<ahref="#"onclick="OpenWin(this)"srclink="<%#"Employee_Update.aspx?E_id="+Eval("E_id")%>">修改</a>对应的JS:<script>functionOpenWin(obj){varlink=obj.srclink;varheight=parseInt

子窗口关闭后父窗口数据更新问题

问题描述 今天写了个简单的通讯录小应用程序,新增和编辑按钮会弹出一个窗口供添加联系人或编辑用的,但是在提交后,之前那个主窗口数据没有更新过来,需要点击查询等按钮执行一次更新才可以.这个BUG怎么修正,用手机敲的,希望得到解答,谢谢!下面是局部代码:Main.javamodify(eve){OperationDialog od = new OperationDialog(this);od.setModal(true);od.initData(aid);od.setVisible(true);ini

如何使子控件和父窗口都能接受到CBN_SELCHANGE事件?

情况是这样的:在对话框中有一个自定义组合框控件CMyComboBox,它继承自MFC类CComboBox.在自定义的组合框中,要处理这样一种情况,如果用户没有改变CMyComboBox的值,则不给父窗口发消息,如果改变了,则通知父窗口以进行其它的更新工作.解决方案如下:  //CMyComboBox.hclass CMyComboBox : public CComboBox{        afx_msg BOOL OnSelchange();    } //CMyComboBox.cppBEG