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”,在父窗体中有个公共刷新方法,也就是窗体数据初始 ...
随机推荐
- myeclipse给项目改了名字,但部署tomcat的项目名还是原来的
如标题所示: 在myeclipse中按F2改了项目名称,之前在tomcat中部署的名称是另一个,再次重新部署,永远是上一个的旧名称 解决办法: 项目点右键-properties-左上角搜索框输入web ...
- java 判断String 是否为空
StringUtils.isBlank(null) = true StringUtils.isBlank("") = true StringUtils.isBlank(" ...
- 电商总结(五)移动M站建设
最近在一直在搞M站,也就是移动web站点.由于是第一次,也遇到了很多问题,所以把最近了解到的东西总结总结.聊一聊什么是移动M站,它有啥作用和优势. 也有人会问,M站和APP有什么不同? 1. APP ...
- CentOS Linux解决Device eth0 does not seem to be present
在VMware里克隆出来的Centos Linux.. ifconfig...没有看到eth0..然后重启网卡又报下面错误. 故障现象: 解决办法: 首先,打开/etc/udev/rules.d/70 ...
- eclipse中导入jar文件的源码
有时候想看看一个jar包的源码是怎么写的,想按Ctrl+鼠标左键点击来自动导航这时候就需要先把源码给导入到eclipse中,步骤如下:首先准备jar包和源文件包比如:
- 转:C#中TransactionScope的使用方法和原理
在.net 1.1的时代,还没有TransactionScope类,因此很多关于事务的处理,都交给了SqlTransaction和SqlConnection,每个Transaction是基于每个Con ...
- Shell case esac语句
case ... esac 与其他语言中的 switch ... case 语句类似,是一种多分枝选择结构. case 语句匹配一个值或一个模式,如果匹配成功,执行相匹配的命令.case语句格式如下: ...
- Node.js Stream-基础篇
Node.js Stream - 基础篇 邹斌 ·2016-07-08 11:51 背景 在构建较复杂的系统时,通常将其拆解为功能独立的若干部分.这些部分的接口遵循一定的规范,通过某种方式相连,以共同 ...
- PHP通过ini_set()来设置显示错误信息和执行时间
PHP的 ini_set函数是设置选项中的值,在执行函数后生效,脚本结束的时候,这个设置也失效.不是所有的选项都能被改函数设置的.具体那些值能够设置,可以查看手册中的列表. 就是能够设置php.ini ...
- iptables4张表5条链
4张表:filter nat mangle raw filter:协议过滤: nat:地址转换,端口映射等: mangle:协议修改 TTL等: raw:This table is used m ...