Delphi代码 转C#代码 就两句话

flurrying 2007-12-21 05:24:33
FrmMain.ParentWindow:=StrToInt(Edt3.Text);
BringWindowToTop(FrmMain.Handle);
...全文
153 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
flurrying 2007-12-22
  • 打赏
  • 举报
回复
错误 1 非静态的字段、方法或属性“System.Windows.Forms.Control.Handle.get”要求对象引用 135 \test\test1221\test1221\Form1.cs 27 test1221

错误代码:FrmMain.Handle

这是什么原因呀!
lextm 2007-12-22
  • 打赏
  • 举报
回复
FrmMain.Handle

改成this.Handle
王集鹄 2007-12-21
  • 打赏
  • 举报
回复
参考如下代码:
using System.Runtime.InteropServices;

[DllImport("user32.dll")]
public static extern bool BringWindowToTop(IntPtr hWnd);

[DllImport("user32.dll")]
public static extern bool SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

private void button1_Click(object sender, EventArgs e)
{
SetParent(FrmMain.Handle, (IntPtr)int.Parse(textBox1.Text));
BringWindowToTop(FrmMain.Handle);
}
王集鹄 2007-12-21
  • 打赏
  • 举报
回复
大概是这样
using System.Runtime.InteropServices;

[DllImport("user32.dll")]
public static extern bool BringWindowToTop(IntPtr hWnd);

[DllImport("user32.dll")]
public static extern bool SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

private void button1_Click(object sender, EventArgs e)
{
SetParent(FrmMain.Handle, (IntPtr)int.Parse(textBox3.Text));
BringWindowToTop(FrmMain.Handle);
}
cangwu_lee 2007-12-21
  • 打赏
  • 举报
回复

第一句,ParentWindow,好像C#沒有直接的屬性,那可以用 SetParent 等的API。
第二句,就不用說了吧。BringWindowToTop 也是 WIN32 API來的。

個人認為,LZ 不是不懂DELPHI,而是不懂C#。

cangwu_lee 2007-12-21
  • 打赏
  • 举报
回复
第一句的 ParentWindow 可以用 SetParent 等的API。
第二句,就不用說了吧。

個人認為,LZ 不是不懂DELPHI,而是不懂C#。

lsj_zrp 2007-12-21
  • 打赏
  • 举报
回复
下面一个好像是这样的:
Form5 frm = new Form5();
frm.Location = new Point(170,0);
frm.Size = new Size(Screen.PrimaryScreen.WorkingArea.Width - 170, Screen.PrimaryScreen.WorkingArea.Height);
frm.Show();
lsj_zrp 2007-12-21
  • 打赏
  • 举报
回复
下面一个好像是这样的:
Form5 frm = new Form5();
frm.Location = new Point(170,0);
frm.Size = new Size(Screen.PrimaryScreen.WorkingArea.Width - 170, Screen.PrimaryScreen.WorkingArea.Height);
frm.Show();
lsj_zrp 2007-12-21
  • 打赏
  • 举报
回复
下面一个好像是这样的:
Form5 frm = new Form5();
frm.Location = new Point(170,0);
frm.Size = new Size(Screen.PrimaryScreen.WorkingArea.Width - 170, Screen.PrimaryScreen.WorkingArea.Height);
frm.Show();
lsj_zrp 2007-12-21
  • 打赏
  • 举报
回复
上面一个:
Form5 frm = new Form5();
frm.Show();
frm.ParentForm = this;
frm.BringToFront();
flurrying 2007-12-21
  • 打赏
  • 举报
回复
还有这一句!
MoveWindow(StrToInt(Edt2.Text),170,0,screen.Width-170,screen.Height,False);

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧