B窗体继承于A窗体,B启动:问题点
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, ExtCtrls;
- type
- TForm1 = class(TForm)
- pnl1: TPanel;
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- end.
- //---------
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, Unit1, ExtCtrls;
- type
- TForm2 = class(TForm1) // 继承于TForm1类
- pnl2: TPanel;
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form2: TForm2;
- implementation
- {$R *.dfm}
- end.
代码
- object Form1: TForm1
- Left =
- Top =
- Width =
- Height =
- Caption = 'Form1'
- Color = clBtnFace
- Font.Charset = DEFAULT_CHARSET
- Font.Color = clWindowText
- Font.Height = -
- Font.Name = 'MS Sans Serif'
- Font.Style = []
- OldCreateOrder = False
- PixelsPerInch =
- TextHeight =
- object pnl1: TPanel
- Left =
- Top =
- Width =
- Height =
- Caption = 'pnl1'
- Color = clSkyBlue
- TabOrder =
- end
- end
- //------------
- inherited Form2: TForm2
- Width =
- Height =
- Caption = 'Form2'
- PixelsPerInch =
- TextHeight =
- inherited pnl1: TPanel
- Left =
- Top =
- Width =
- Height =
- end
- object pnl2: TPanel
- Left =
- Top =
- Width =
- Height =
- Caption = 'pnl2'
- Color =
- TabOrder =
- end
- end
窗体代码
Delphi2C#工具转换后,有异常无法编译
仅需要改 //Unit2.Designer.cs
- namespace Unit2
- {
- partial class TForm2
- {
- public System.Windows.Forms.Panel pnl1;
- public System.Windows.Forms.Panel pnl2;
- #region Windows Form Designer generated code
- private void InitializeComponent()
- {
- this.pnl1 = new System.Windows.Forms.Panel();
- this.pnl2 = new System.Windows.Forms.Panel();
- this.pnl1.Size = new System.Drawing.Size(, );
- this.pnl1.Location = new System.Drawing.Point(, );
- this.pnl1.Enabled = true;
- this.pnl1.Name = "pnl1";
- this.pnl1.BackColor = System.Drawing.SystemColors.ButtonFace;
- this.pnl2.Size = new System.Drawing.Size(, );
- this.pnl2.Location = new System.Drawing.Point(, );
- this.pnl2.Enabled = true;
- this.pnl2.TabIndex = ;
- this.pnl2.Name = "pnl2";
- this.pnl2.Text = "pnl2";
- this.pnl2.BackColor = ;
- }
- #endregion
- }
- }
这是生成的默认代码
- //这是修改后的代码
- namespace Unit2
- {
- partial class TForm2
- {
- //public System.Windows.Forms.Panel pnl1;// 第一处屏蔽
- public System.Windows.Forms.Panel pnl2;
- #region Windows Form Designer generated code
- private void InitializeComponent()
- {
- //this.pnl1 = new System.Windows.Forms.Panel(); 第二 屏蔽
- this.pnl2 = new System.Windows.Forms.Panel();
- this.SuspendLayout();
- //
- // pnl1
- //
- this.pnl1.BackColor = System.Drawing.SystemColors.MenuHighlight; //第二并列 在窗体改panel颜色,就自动加了这三句话
- this.pnl1.Location = new System.Drawing.Point(, );
- this.pnl1.Size = new System.Drawing.Size(, );
- //
- // pnl2
- //
- this.pnl2.BackColor = System.Drawing.Color.AliceBlue;//第三改颜色值
- this.pnl2.Location = new System.Drawing.Point(, );
- this.pnl2.Name = "pnl2";
- this.pnl2.Size = new System.Drawing.Size(, );
- this.pnl2.TabIndex = ;
- this.pnl2.Text = "pnl2";
- //
- // TForm2 //第四 加以下一段代码
- //
- this.ClientSize = new System.Drawing.Size(, );
- this.Controls.Add(this.pnl2);
- this.Location = new System.Drawing.Point(, );
- this.Name = "TForm2";
- this.Text = "Form1-form2";
- this.Controls.SetChildIndex(this.pnl1, );
- this.Controls.SetChildIndex(this.pnl2, );
- this.ResumeLayout(false);
- }
- #endregion
- }
- }
、、-----------以下为错误的,不用看
- using System;
- using System.Windows.Forms;
- using Unit1;
- using Unit2;
- namespace Project1.Units
- {
- public class Project1
- {
- // Form1
- // Form2
- [STAThread]
- public static void Main(string[] args)
- {
- // Application.Initialize;
- Unit1.Units.Unit1.Form1 = new TForm1();
- Unit2.Units.Unit2.Form2 = new TForm2();
- // Application.Run;
- Application.Run(Unit2.Units.Unit2.Form2);//改第一处,这默认是Form1先启动,要改成Form2
- }
- } // end Project1
- }
改第一处
- namespace Unit1
- {
- partial class TForm1
- {
- public System.Windows.Forms.Panel pnl1;
- private System.ComponentModel.Container components = null;
- private System.Windows.Forms.ToolTip toolTip1 = null;
- // Clean up any resources being used.
- protected override void Dispose(bool disposing)
- {
- if(disposing)
- {
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose(disposing);
- }
- #region Windows Form Designer generated code
- private void InitializeComponent()
- {
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(this.GetType());
- this.components = new System.ComponentModel.Container();
- this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
- this.pnl1 = new System.Windows.Forms.Panel();
- this.SuspendLayout();
- this.Location = new System.Drawing.Point(, );
- this.ClientSize = new System.Drawing.Size(, );
- this.Font = new System.Drawing.Font("MS Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point ,((byte)()));
- this.BackColor = System.Drawing.SystemColors.ButtonFace;
- this.Name = "Form1";
- this.Text = "Form1";
- this.AutoScroll = true;
- this.pnl1.Size = new System.Drawing.Size(, );
- this.pnl1.Location = new System.Drawing.Point(, );
- this.pnl1.Enabled = true;
- this.pnl1.TabIndex = ;
- this.pnl1.Name = "pnl1";
- this.pnl1.Text = "pnl1";
- this.pnl1.BackColor = ; //System.Drawing.Color.SkyBlue; 改第二处,这里要写成这样的格式
- this.Controls.Add(pnl1);
- this.ResumeLayout(false);
- }
- #endregion
- }
- }
改第二处
B窗体继承于A窗体,B启动:问题点的更多相关文章
- vb.net之窗体继承
相信很多自己动手敲过完整程序的同学都会发现,其实我们敲的很多窗体布局都非常的相似,有的部分用到的控件甚至一模一样,如果每一个窗体都自己重新摆放或者复制粘贴虽然没有问题,但是有时候若是修改其中一小点位置 ...
- windows窗体继承问题
窗体继承什么时候用的到呢?当我们使用三层架构来编写我们的cs程序时,我们的U层大部分是windows窗体.这个时候如果我们有一些公共变量,或者是一个窗体需要使用另一个窗体的数据.或者是有一些用于判断的 ...
- Delphi - 子窗体继承父窗体后如何显示父窗体上的控件
1.创建子窗体Form1 File -> New -> Form,新建一个form,在form的单元文件中修改 2.子窗体中引用父窗体单元 uses TFatherForm 3.将子窗体中 ...
- WinForm窗体继承
在Windows应用程序中,从现有的窗体继承,查看子窗体的设计视图时,会出现错误: 服务容器中已存在服务 System.Windows.Forms.Design.IEventHandlerServic ...
- WinForm窗体继承自定义的模板窗体出错
在开发Winform程序的时候,我们往往需要根据需要做一些自定义的控件模块,这样可以给系统模块重复利用,或者实现更好的效果等功能.而今天自定义一个窗体,然后子窗体继承的时候出现了一点问题. 问题: 在 ...
- .NET重构(四):窗体继承+模板方法,完美实现组合查询
导读:在机房重构中,有好些个查询都是大同小异,最为显著的就是组合查询了.怎样给自己省事儿,相同的东西能不能重复利用,就成了一个现实的问题.第一遍做机房的时候,使用的更多的是:复制+粘贴.学习了设计模式 ...
- PyQt5学习笔记-从主窗体打开一个子窗体
PyQt5学习笔记-从主窗体打开一个子窗体 软件环境: Eric6+Python3.5+PyQt5 试验目标: 1.点击菜单项Open,打开一个子窗体 2.点击按钮Open,打开一个子窗体 主窗体设计 ...
- winform里操作打开在panel里的form窗体,子窗体操作同级子窗体或者父窗体的方法
最近开始了一个winform项目,原先一直都是web项目.遇到个问题,就是在框架内,左侧和中间的main都是用panel来实现的form,就是把form窗体打开到panel里,实现左侧是导航,中间是操 ...
- winform打开子窗体后,在子窗体中刷新父窗体,或者关闭子窗体刷新父窗体
winform打开子窗体后,在子窗体中刷新父窗体,或者关闭子窗体刷新父窗体,搜集了几个方法,列举如下: 一 . 所有权法 父窗体,名称为“fuForm”,在父窗体中有个公共刷新方法,也就是窗体数据初始 ...
随机推荐
- <<< sqlserver评估过期解决
点击开始-所有程序-Microsoft SQL Server 2008-配置工具-SQL Server 安装中心然后点击左侧的维护,在点击右侧的版本升级,接着按照提示一直点下一步,到产品密钥的时候输入 ...
- 正则去掉img标签的style样式
$body = '<div style="width:100px; height:20px;"><img alt="test" src=&qu ...
- Python Day4
一.装饰器 装饰器类似于一种动态增加函数功能的方法,使用@语法,放在它要装饰的函数定义处(函数定义的上面),实现为已经存在的函数增加新的功能. def outer(func): def innter( ...
- 【迁移】—Entity Framework实例详解 转
一.Entity Framework 迁移命令(get-help EntityFramework) Enable-Migrations 启用迁移 Add-Migration 为挂起的Model变化添加 ...
- 学习MySQL之单表操作(二)
##单表操作 ##创建表 CREATE TABLE t_employee( empno ), ename ), job ), MGR ), Hiredate DATE DEFAULT '0000-00 ...
- JDBC ODBC区别
一.JDBC(Java DataBase Connectivity standard) 1.JDBC,它是一个面向对象的应用程序接口(API), 通过它可访问各类关系数据库. 2. 驱动程序(JDBC ...
- [Data Structure] 数据结构中各种树
数据结构中有很多树的结构,其中包括二叉树.二叉搜索树.2-3树.红黑树等等.本文中对数据结构中常见的几种树的概念和用途进行了汇总,不求严格精准,但求简单易懂. 1. 二叉树 二叉树是数据结构中一种重要 ...
- 【Alpha版本】 第二天 11.8
一.站立式会议照片: 二.项目燃尽图: 三.项目进展: 成 员 昨天完成任务 今天完成任务 明天要做任务 问题困难 心得体会 胡泽善 我要招聘详情的展示 注册界面的实现 填写招聘时用户填写各个日期到可 ...
- JavaScript方法
1.hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象.不过需要注意的是,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员.isPrototype ...
- 曲线救国:IIS7集成模式下如何获取网站的URL
如果我们在Global中的Application_Start事件中访问HttpContext.Current.Request对象,如: protected void Application_Start ...