1. uses
  2. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  3. Dialogs, ExtCtrls;
  4.  
  5. type
  6. TForm1 = class(TForm)
  7. pnl1: TPanel;
  8. private
  9. { Private declarations }
  10. public
  11. { Public declarations }
  12. end;
  13.  
  14. var
  15. Form1: TForm1;
  16.  
  17. implementation
  18.  
  19. {$R *.dfm}
  20.  
  21. end.
  22. //---------
  23. uses
  24. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  25. Dialogs, Unit1, ExtCtrls;
  26.  
  27. type
  28. TForm2 = class(TForm1) // 继承于TForm1类
  29. pnl2: TPanel;
  30. private
  31. { Private declarations }
  32. public
  33. { Public declarations }
  34. end;
  35.  
  36. var
  37. Form2: TForm2;
  38.  
  39. implementation
  40.  
  41. {$R *.dfm}
  42.  
  43. end.

代码

  1. object Form1: TForm1
  2. Left =
  3. Top =
  4. Width =
  5. Height =
  6. Caption = 'Form1'
  7. Color = clBtnFace
  8. Font.Charset = DEFAULT_CHARSET
  9. Font.Color = clWindowText
  10. Font.Height = -
  11. Font.Name = 'MS Sans Serif'
  12. Font.Style = []
  13. OldCreateOrder = False
  14. PixelsPerInch =
  15. TextHeight =
  16. object pnl1: TPanel
  17. Left =
  18. Top =
  19. Width =
  20. Height =
  21. Caption = 'pnl1'
  22. Color = clSkyBlue
  23. TabOrder =
  24. end
  25. end
  26. //------------
  27. inherited Form2: TForm2
  28. Width =
  29. Height =
  30. Caption = 'Form2'
  31. PixelsPerInch =
  32. TextHeight =
  33. inherited pnl1: TPanel
  34. Left =
  35. Top =
  36. Width =
  37. Height =
  38. end
  39. object pnl2: TPanel
  40. Left =
  41. Top =
  42. Width =
  43. Height =
  44. Caption = 'pnl2'
  45. Color =
  46. TabOrder =
  47. end
  48. end

窗体代码

Delphi2C#工具转换后,有异常无法编译

仅需要改 //Unit2.Designer.cs

  1. namespace Unit2
  2. {
  3. partial class TForm2
  4. {
  5. public System.Windows.Forms.Panel pnl1;
  6. public System.Windows.Forms.Panel pnl2;
  7.  
  8. #region Windows Form Designer generated code
  9. private void InitializeComponent()
  10. {
  11. this.pnl1 = new System.Windows.Forms.Panel();
  12. this.pnl2 = new System.Windows.Forms.Panel();
  13. this.pnl1.Size = new System.Drawing.Size(, );
  14. this.pnl1.Location = new System.Drawing.Point(, );
  15. this.pnl1.Enabled = true;
  16. this.pnl1.Name = "pnl1";
  17. this.pnl1.BackColor = System.Drawing.SystemColors.ButtonFace;
  18. this.pnl2.Size = new System.Drawing.Size(, );
  19. this.pnl2.Location = new System.Drawing.Point(, );
  20. this.pnl2.Enabled = true;
  21. this.pnl2.TabIndex = ;
  22. this.pnl2.Name = "pnl2";
  23. this.pnl2.Text = "pnl2";
  24. this.pnl2.BackColor = ;
  25. }
  26. #endregion
  27.  
  28. }
  29. }

这是生成的默认代码

  1. //这是修改后的代码
  2. namespace Unit2
  3. {
  4. partial class TForm2
  5. {
  6. //public System.Windows.Forms.Panel pnl1;// 第一处屏蔽
  7. public System.Windows.Forms.Panel pnl2;
  8.  
  9. #region Windows Form Designer generated code
  10. private void InitializeComponent()
  11. {
  12. //this.pnl1 = new System.Windows.Forms.Panel(); 第二 屏蔽
  13. this.pnl2 = new System.Windows.Forms.Panel();
  14. this.SuspendLayout();
  15. //
  16. // pnl1
  17. //
  18. this.pnl1.BackColor = System.Drawing.SystemColors.MenuHighlight; //第二并列 在窗体改panel颜色,就自动加了这三句话
  19. this.pnl1.Location = new System.Drawing.Point(, );
  20. this.pnl1.Size = new System.Drawing.Size(, );
  21. //
  22. // pnl2
  23. //
  24. this.pnl2.BackColor = System.Drawing.Color.AliceBlue;//第三改颜色值
  25. this.pnl2.Location = new System.Drawing.Point(, );
  26. this.pnl2.Name = "pnl2";
  27. this.pnl2.Size = new System.Drawing.Size(, );
  28. this.pnl2.TabIndex = ;
  29. this.pnl2.Text = "pnl2";
  30. //
  31. // TForm2 //第四 加以下一段代码
  32. //
  33. this.ClientSize = new System.Drawing.Size(, );
  34. this.Controls.Add(this.pnl2);
  35. this.Location = new System.Drawing.Point(, );
  36. this.Name = "TForm2";
  37. this.Text = "Form1-form2";
  38. this.Controls.SetChildIndex(this.pnl1, );
  39. this.Controls.SetChildIndex(this.pnl2, );
  40. this.ResumeLayout(false);
  41.  
  42. }
  43. #endregion
  44.  
  45. }
  46. }

、、-----------以下为错误的,不用看

  1. using System;
  2. using System.Windows.Forms;
  3. using Unit1;
  4. using Unit2;
  5. namespace Project1.Units
  6. {
  7. public class Project1
  8. {
  9. // Form1
  10. // Form2
  11. [STAThread]
  12. public static void Main(string[] args)
  13. {
  14. // Application.Initialize;
  15. Unit1.Units.Unit1.Form1 = new TForm1();
  16. Unit2.Units.Unit2.Form2 = new TForm2();
  17. // Application.Run;
  18. Application.Run(Unit2.Units.Unit2.Form2);//改第一处,这默认是Form1先启动,要改成Form2
  19. }
  20.  
  21. } // end Project1
  22.  
  23. }

改第一处

  1. namespace Unit1
  2. {
  3. partial class TForm1
  4. {
  5. public System.Windows.Forms.Panel pnl1;
  6. private System.ComponentModel.Container components = null;
  7. private System.Windows.Forms.ToolTip toolTip1 = null;
  8.  
  9. // Clean up any resources being used.
  10. protected override void Dispose(bool disposing)
  11. {
  12. if(disposing)
  13. {
  14. if(components != null)
  15. {
  16. components.Dispose();
  17. }
  18. }
  19. base.Dispose(disposing);
  20. }
  21.  
  22. #region Windows Form Designer generated code
  23. private void InitializeComponent()
  24. {
  25. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(this.GetType());
  26. this.components = new System.ComponentModel.Container();
  27. this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
  28. this.pnl1 = new System.Windows.Forms.Panel();
  29. this.SuspendLayout();
  30. this.Location = new System.Drawing.Point(, );
  31. this.ClientSize = new System.Drawing.Size(, );
  32. this.Font = new System.Drawing.Font("MS Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point ,((byte)()));
  33. this.BackColor = System.Drawing.SystemColors.ButtonFace;
  34. this.Name = "Form1";
  35. this.Text = "Form1";
  36. this.AutoScroll = true;
  37. this.pnl1.Size = new System.Drawing.Size(, );
  38. this.pnl1.Location = new System.Drawing.Point(, );
  39. this.pnl1.Enabled = true;
  40. this.pnl1.TabIndex = ;
  41. this.pnl1.Name = "pnl1";
  42. this.pnl1.Text = "pnl1";
  43. this.pnl1.BackColor = ; //System.Drawing.Color.SkyBlue; 改第二处,这里要写成这样的格式
  44. this.Controls.Add(pnl1);
  45. this.ResumeLayout(false);
  46. }
  47. #endregion
  48.  
  49. }
  50. }

改第二处

B窗体继承于A窗体,B启动:问题点的更多相关文章

  1. vb.net之窗体继承

    相信很多自己动手敲过完整程序的同学都会发现,其实我们敲的很多窗体布局都非常的相似,有的部分用到的控件甚至一模一样,如果每一个窗体都自己重新摆放或者复制粘贴虽然没有问题,但是有时候若是修改其中一小点位置 ...

  2. windows窗体继承问题

    窗体继承什么时候用的到呢?当我们使用三层架构来编写我们的cs程序时,我们的U层大部分是windows窗体.这个时候如果我们有一些公共变量,或者是一个窗体需要使用另一个窗体的数据.或者是有一些用于判断的 ...

  3. Delphi - 子窗体继承父窗体后如何显示父窗体上的控件

    1.创建子窗体Form1 File -> New -> Form,新建一个form,在form的单元文件中修改 2.子窗体中引用父窗体单元 uses TFatherForm 3.将子窗体中 ...

  4. WinForm窗体继承

    在Windows应用程序中,从现有的窗体继承,查看子窗体的设计视图时,会出现错误: 服务容器中已存在服务 System.Windows.Forms.Design.IEventHandlerServic ...

  5. WinForm窗体继承自定义的模板窗体出错

    在开发Winform程序的时候,我们往往需要根据需要做一些自定义的控件模块,这样可以给系统模块重复利用,或者实现更好的效果等功能.而今天自定义一个窗体,然后子窗体继承的时候出现了一点问题. 问题: 在 ...

  6. .NET重构(四):窗体继承+模板方法,完美实现组合查询

    导读:在机房重构中,有好些个查询都是大同小异,最为显著的就是组合查询了.怎样给自己省事儿,相同的东西能不能重复利用,就成了一个现实的问题.第一遍做机房的时候,使用的更多的是:复制+粘贴.学习了设计模式 ...

  7. PyQt5学习笔记-从主窗体打开一个子窗体

    PyQt5学习笔记-从主窗体打开一个子窗体 软件环境: Eric6+Python3.5+PyQt5 试验目标: 1.点击菜单项Open,打开一个子窗体 2.点击按钮Open,打开一个子窗体 主窗体设计 ...

  8. winform里操作打开在panel里的form窗体,子窗体操作同级子窗体或者父窗体的方法

    最近开始了一个winform项目,原先一直都是web项目.遇到个问题,就是在框架内,左侧和中间的main都是用panel来实现的form,就是把form窗体打开到panel里,实现左侧是导航,中间是操 ...

  9. winform打开子窗体后,在子窗体中刷新父窗体,或者关闭子窗体刷新父窗体

    winform打开子窗体后,在子窗体中刷新父窗体,或者关闭子窗体刷新父窗体,搜集了几个方法,列举如下: 一 . 所有权法 父窗体,名称为“fuForm”,在父窗体中有个公共刷新方法,也就是窗体数据初始 ...

随机推荐

  1. <<< sqlserver评估过期解决

    点击开始-所有程序-Microsoft SQL Server 2008-配置工具-SQL Server 安装中心然后点击左侧的维护,在点击右侧的版本升级,接着按照提示一直点下一步,到产品密钥的时候输入 ...

  2. 正则去掉img标签的style样式

    $body = '<div style="width:100px; height:20px;"><img alt="test" src=&qu ...

  3. Python Day4

    一.装饰器 装饰器类似于一种动态增加函数功能的方法,使用@语法,放在它要装饰的函数定义处(函数定义的上面),实现为已经存在的函数增加新的功能. def outer(func): def innter( ...

  4. 【迁移】—Entity Framework实例详解 转

    一.Entity Framework 迁移命令(get-help EntityFramework) Enable-Migrations 启用迁移 Add-Migration 为挂起的Model变化添加 ...

  5. 学习MySQL之单表操作(二)

    ##单表操作 ##创建表 CREATE TABLE t_employee( empno ), ename ), job ), MGR ), Hiredate DATE DEFAULT '0000-00 ...

  6. JDBC ODBC区别

    一.JDBC(Java DataBase Connectivity standard) 1.JDBC,它是一个面向对象的应用程序接口(API), 通过它可访问各类关系数据库. 2. 驱动程序(JDBC ...

  7. [Data Structure] 数据结构中各种树

    数据结构中有很多树的结构,其中包括二叉树.二叉搜索树.2-3树.红黑树等等.本文中对数据结构中常见的几种树的概念和用途进行了汇总,不求严格精准,但求简单易懂. 1. 二叉树 二叉树是数据结构中一种重要 ...

  8. 【Alpha版本】 第二天 11.8

    一.站立式会议照片: 二.项目燃尽图: 三.项目进展: 成 员 昨天完成任务 今天完成任务 明天要做任务 问题困难 心得体会 胡泽善 我要招聘详情的展示 注册界面的实现 填写招聘时用户填写各个日期到可 ...

  9. JavaScript方法

    1.hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象.不过需要注意的是,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员.isPrototype ...

  10. 曲线救国:IIS7集成模式下如何获取网站的URL

    如果我们在Global中的Application_Start事件中访问HttpContext.Current.Request对象,如: protected void Application_Start ...