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启动:问题点的更多相关文章

  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. supervisord安装使用简记

    What is supervisor Supervisor is a client/server system that allows its users to monitor and control ...

  2. Linux下查看软件的安装路径

    一.which 命令 Shell 的which 命令可以找出相关命令是否已经在搜索路径中. $ which git/usr/bin/git 二.whereis 命令 whereis 命令搜索更大范围的 ...

  3. Python Day10

    进程 在python中multiprocess模块提供了Process类,实现进程相关的功能.但是,由于它是基于fork机制的,因此不被windows平台支持.想要在windows中运行,必须使用if ...

  4. 面试题目——《CC150》树与图

    面试题4.1:实现一个函数,检查二叉树是否平衡.在这个问题中,平衡树的定义如下:任意一个结点,其两颗子树的高度差不超过1. 思路:两个方法,第一种速度较快 package cc150; public ...

  5. 修改Excel2013默认模版(启动模版和新建Sheet模版)

    1.  C:\Windows\ShellNew\EXCEL12.XLSX 设置好格式后另存为, 然后复制过来覆盖掉,如果覆盖不了,注意修改所有者权限 2. 新建文件保存为模版文件Sheet.xltx, ...

  6. [转] Unity Mathf 数学运算(C#)

    Mathf.Abs 绝对值 计算并返回指定参数 f 绝对值. Mathf.Acos 反余弦 static function Acos (f : float) : float 以弧度为单位计算并返回参数 ...

  7. .edmx 文件概述(实体框架)

    (一) 认识.edmx文件结构 参考资料: .edmx 文件概述(实体框架) Entity Framework 全面教程详解(转) Entity Framework 教程 Entity Framewo ...

  8. AngularJS常用插件与指令收集

    angularjs 组件列表 bindonce UI-Router Angular Tree angular-ngSanitize模块-$sanitize服务详解 使用 AngularJS 开发一个大 ...

  9. 1.0、Struts2的简单搭建方法

    一.Struts2:是一个基于MVC设计模式的Web应用框架,它本质上相当于一个servlet:用于jsp页面与Java代码之间的交互. 1.核心:Filter拦截器,对所有的请求进行拦截. 2.工作 ...

  10. codevs2777 栅栏的木料

    题目描述 Description 农民John准备建一个栅栏来围住他的牧场.他已经确定了栅栏的形状,但是他在木料方面有些问题.当地的杂货储存商扔给John一些木板,而John必须从这些木板中找出尽可能 ...