newsgroups-index (beta)

Current group: microsoft.public.cn.dotnet.languages.csharp

C#的mdi窗体问题

C#的mdi窗体问题  
Ben
 =?gb2312?B?UmU6IEMjtcRtZGm0sMzlzsrM4g==?=  
Vince Yuan
From:Ben
Subject:C#的mdi窗体问题
Date:Tue, 18 Jan 2005 11:21:17 +0800
请问:

在C#的mdi内,开了许多子窗体。

我想将某一个激活,代码是?

exp:
现在已经启动了一个叫form1的,但不是当前活动的.
我想将他激活
From:Vince Yuan
Subject:=?gb2312?B?UmU6IEMjtcRtZGm0sMzlzsrM4g==?=
Date:Tue, 18 Jan 2005 12:06:30 +0800
This is a multi-part message in MIME format.

------=_NextPart_000_0013_01C4FD56.24D462D0
Content-Type: text/plain;
charset="gb2312"
Content-Transfer-Encoding: quoted-printable

Activates the form and gives it focus.

[Visual Basic]
Public Sub Activate()
[C#]
public void Activate();
[C++]
public: void Activate();
[JScript]
public function Activate();
Remarks
Activating a form brings it to the front if this is the active =
application, or it flashes the window caption if this is not the active =
application. The form must be visible for this method to have any =
effect. To determine the active form in an application, use the =
ActiveForm property or the ActiveMdiChild property if your forms are in =
a Multiple Document Interface (MDI) application.

Example
[Visual Basic, C#] The following code example demonstrates how to use =
the SetDesktopLocation, Load and Activate members. To run the example, =
paste the following code in a form called Form1 containing a button =
called Button1 and two Label controls called Label1 and Label2. Ensure =
all events are connected to their event-handling methods.

[Visual Basic]=20
Shared x As Integer =3D 200
Shared y As Integer =3D 200

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

' Create a new Form1 and set its Visible property to true.
Dim form2 As New Form1
form2.Visible =3D True

' Set the new form's desktop location so it appears below and=20
' to the right of the current form.
form2.SetDesktopLocation(x, y)
x +=3D 30
y +=3D 30

' Keep the current form active by calling the Activate method.
Me.Activate()
Me.Button1.Enabled =3D False
End Sub



' Updates the label text to reflect the current values of x and y,=20
' which was were incremented in the Button1 control's click event.
Private Sub Form1_Activated(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Activated
Label1.Text =3D "x: " & x & " y: " & y
Label2.Text =3D "Number of forms currently open: " & count
End Sub

Shared count As Integer =3D 0

Private Sub Form1_Closed(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Closed
count -=3D 1
End Sub

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
count +=3D 1
End Sub
[C#]=20
static int x =3D 200;
static int y =3D 200;

private void Button1_Click(System.Object sender,=20
System.EventArgs e)
{
// Create a new Form1 and set its Visible property to true.
Form1 form2 =3D new Form1();
form2.Visible =3D true;

// Set the new form's desktop location so it =20
// appears below and to the right of the current form.
form2.SetDesktopLocation(x, y);
x +=3D 30;
y +=3D 30;

// Keep the current form active by calling the Activate
// method.
this.Activate();
this.Button1.Enabled =3D false;
}



// Updates the label text to reflect the current values of x=20
// and y, which was were incremented in the Button1 control's=20
// click event.
private void Form1_Activated(object sender, System.EventArgs e)
{
Label1.Text =3D "x: "+x+" y: "+y;
Label2.Text =3D "Number of forms currently open: "+count;
}

static int count =3D 0;

private void Form1_Closed(object sender, System.EventArgs e)
{
count -=3D 1;
}

private void Form1_Load(object sender, System.EventArgs e)
{
count +=3D 1;
}
--=20
Vince


"Ben" wrote in message =
news:umY3DzQ$EHA.824@TK2MSFTNGP11.phx.gbl...
> =C7=EB=CE=CA=A3=BA
>=20
> =
=D4=DAC#=B5=C4mdi=C4=DA=A3=AC=BF=AA=C1=CB=D0=ED=B6=E0=D7=D3=B4=B0=CC=E5=A1=
=A3
>=20
> =
=CE=D2=CF=EB=BD=AB=C4=B3=D2=BB=B8=F6=BC=A4=BB=EE=A3=AC=B4=FA=C2=EB=CA=C7=A3=
=BF
>=20
> exp:
> =
=CF=D6=D4=DA=D2=D1=BE=AD=C6=F4=B6=AF=C1=CB=D2=BB=B8=F6=BD=D0form1=B5=C4,=B5=
=AB=B2=BB=CA=C7=B5=B1=C7=B0=BB=EE=B6=AF=B5=C4.
> =CE=D2=CF=EB=BD=AB=CB=FB=BC=A4=BB=EE=20
>=20
>
------=_NextPart_000_0013_01C4FD56.24D462D0
Content-Type: text/html;
charset="gb2312"
Content-Transfer-Encoding: quoted-printable









Activates the form and gives it focus.

style=3D"DISPLAY: none">none">[Visual Basic]
Public Sub Activate()

style=3D"DISPLAY: none">[C#]
public href=3D"ms-help://MS.MSDNQTR.2004APR.1033/cpref/html/frlrfsystemvoidclass=
topic.htm">void
Activate();

style=3D"DISPLAY: none">[C++]
public: href=3D"ms-help://MS.MSDNQTR.2004APR.1033/cpref/html/frlrfsystemvoidclass=
topic.htm">void
Activate();

style=3D"DISPLAY: none">[JScript]
public function Activate();


Remarks


Activating a form brings it to the front if this is the active =
application,=20
or it flashes the window caption if this is not the active application. =
The form=20
must be visible for this method to have any effect. To determine the =
active form=20
in an application, use the href=3D"ms-help://MS.MSDNQTR.2004APR.1033/cpref/html/frlrfsystemwindowsfo=
rmsformclassactiveformtopic.htm">ActiveForm=20
property or the href=3D"ms-help://MS.MSDNQTR.2004APR.1033/cpref/html/frlrfsystemwindowsfo=
rmsformclassactivemdichildtopic.htm">ActiveMdiChild=20
property if your forms are in a Multiple Document Interface (MDI)=20
application.


Example


style=3D"DISPLAY: none">[Visual Basic, C#] The =
following code=20
example demonstrates how to use the href=3D"ms-help://MS.MSDNQTR.2004APR.1033/cpref/html/frlrfsystemwindowsfo=
rmsformclasssetdesktoplocationtopic.htm">SetDesktopLocation,=20
href=3D"ms-help://MS.MSDNQTR.2004APR.1033/cpref/html/frlrfsystemwindowsfo=
rmsformclassloadtopic.htm">Load=20
and Activate members. To run the example, paste the following =
code in a=20
form called Form1 containing a button called Button1 and two Label =
controls=20
called Label1 and Label2. Ensure all events are connected to their=20
event-handling methods.

none">none">[Visual Basic]=20
Shared x As Integer =3D 200
Shared y As Integer =3D 200

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

' Create a new Form1 and set its Visible property to true.
Dim form2 As New Form1
form2.Visible =3D True

' Set the new form's desktop location so it appears below and=20
' to the right of the current form.
form2.SetDesktopLocation(x, y)
x +=3D 30
y +=3D 30

' Keep the current form active by calling the Activate method.
Me.Activate()
Me.Button1.Enabled =3D False
End Sub



' Updates the label text to reflect the current values of x and y,=20
' which was were incremented in the Button1 control's click event.
Private Sub Form1_Activated(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Activated
Label1.Text =3D "x: " & x & " y: " & y
Label2.Text =3D "Number of forms currently open: " & count
End Sub

Shared count As Integer =3D 0

Private Sub Form1_Closed(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Closed
count -=3D 1
End Sub

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
count +=3D 1
End Sub

style=3D"DISPLAY: none">[C#]=20
static int x =3D 200;
static int y =3D 200;

private void Button1_Click(System.Object sender,=20
System.EventArgs e)
{
// Create a new Form1 and set its Visible property to true.
Form1 form2 =3D new Form1();
form2.Visible =3D true;

// Set the new form's desktop location so it =20
// appears below and to the right of the current form.
form2.SetDesktopLocation(x, y);
x +=3D 30;
y +=3D 30;

// Keep the current form active by calling the Activate
// method.
this.Activate();
this.Button1.Enabled =3D false;
}



// Updates the label text to reflect the current values of x=20
// and y, which was were incremented in the Button1 control's=20
// click event.
private void Form1_Activated(object sender, System.EventArgs e)
{
Label1.Text =3D "x: "+x+" y: "+y;
Label2.Text =3D "Number of forms currently open: "+count;
}

static int count =3D 0;

private void Form1_Closed(object sender, System.EventArgs e)
{
count -=3D 1;
}

private void Form1_Load(object sender, System.EventArgs e)
{
count +=3D 1;
}


--
Vince

 

 

"Ben" <href=3D"mailto:jiabin@vip.sina.com">size=3D2>jiabin@vip.sina.com> =
wrote in=20
message
href=3D"news:umY3DzQ$EHA.824@TK2MSFTNGP11.phx.gbl">face=3DArial =
size=3D2>news:umY3DzQ$EHA.824@TK2MSFTNGP11.phx.gbl
face=3DArial size=3D2>...
> =
=C7=EB=CE=CA=A3=BA
>=20

> =
=D4=DAC#=B5=C4mdi=C4=DA=A3=AC=BF=AA=C1=CB=D0=ED=B6=E0=D7=D3=B4=B0=CC=E5=A1=
=A3
>
> =
=CE=D2=CF=EB=BD=AB=C4=B3=D2=BB=B8=F6=BC=A4=BB=EE=A3=AC=B4=FA=C2=EB=CA=C7=A3=
=BF
>
>=20
exp:
> =
=CF=D6=D4=DA=D2=D1=BE=AD=C6=F4=B6=AF=C1=CB=D2=BB=B8=F6=BD=D0form1=B5=C4,=B5=
=AB=B2=BB=CA=C7=B5=B1=C7=B0=BB=EE=B6=AF=B5=C4.
> =
=CE=D2=CF=EB=BD=AB=CB=FB=BC=A4=BB=EE
>=20

>


------=_NextPart_000_0013_01C4FD56.24D462D0--
   

Copyright © 2006 newsgroups-index   -   All rights reserved   -   Impressum