博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
B窗体继承于A窗体,B启动:问题点
阅读量:6826 次
发布时间:2019-06-26

本文共 6336 字,大约阅读时间需要 21 分钟。

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 = 201  Top = 123  Width = 333  Height = 305  Caption = 'Form1'  Color = clBtnFace  Font.Charset = DEFAULT_CHARSET  Font.Color = clWindowText  Font.Height = -11  Font.Name = 'MS Sans Serif'  Font.Style = []  OldCreateOrder = False  PixelsPerInch = 96  TextHeight = 13  object pnl1: TPanel    Left = 48    Top = 32    Width = 161    Height = 185    Caption = 'pnl1'    Color = clSkyBlue    TabOrder = 0  endend//------------inherited Form2: TForm2  Width = 324  Height = 320  Caption = 'Form2'  PixelsPerInch = 96  TextHeight = 13  inherited pnl1: TPanel    Left = 32    Top = 64    Width = 105    Height = 161  end  object pnl2: TPanel    Left = 168    Top = 64    Width = 121    Height = 169    Caption = 'pnl2'    Color = 16764159    TabOrder = 1  endend
窗体代码

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(105, 161);            this.pnl1.Location  = new System.Drawing.Point(32, 64);            this.pnl1.Enabled = true;            this.pnl1.Name = "pnl1";            this.pnl1.BackColor = System.Drawing.SystemColors.ButtonFace;            this.pnl2.Size  = new System.Drawing.Size(121, 169);            this.pnl2.Location  = new System.Drawing.Point(168, 64);            this.pnl2.Enabled = true;            this.pnl2.TabIndex = 1;            this.pnl2.Name = "pnl2";            this.pnl2.Text = "pnl2";            this.pnl2.BackColor = 16764159;        }#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(32, 64);            this.pnl1.Size = new System.Drawing.Size(105, 161);            //             // pnl2            //             this.pnl2.BackColor = System.Drawing.Color.AliceBlue;//第三改颜色值            this.pnl2.Location = new System.Drawing.Point(168, 64);            this.pnl2.Name = "pnl2";            this.pnl2.Size = new System.Drawing.Size(121, 169);            this.pnl2.TabIndex = 1;            this.pnl2.Text = "pnl2";            //             // TForm2 //第四 加以下一段代码            //             this.ClientSize = new System.Drawing.Size(394, 275);            this.Controls.Add(this.pnl2);            this.Location = new System.Drawing.Point(0, 0);            this.Name = "TForm2";            this.Text = "Form1-form2";            this.Controls.SetChildIndex(this.pnl1, 0);            this.Controls.SetChildIndex(this.pnl2, 0);            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(201, 123);            this.ClientSize  = new System.Drawing.Size(422, 403);            this.Font  = new System.Drawing.Font("MS Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point ,((byte)(1)));            this.BackColor = System.Drawing.SystemColors.ButtonFace;            this.Name = "Form1";            this.Text = "Form1";            this.AutoScroll = true;            this.pnl1.Size  = new System.Drawing.Size(161, 185);            this.pnl1.Location  = new System.Drawing.Point(80, 72);            this.pnl1.Enabled = true;            this.pnl1.TabIndex = 0;            this.pnl1.Name = "pnl1";            this.pnl1.Text = "pnl1";            this.pnl1.BackColor = 54545; //System.Drawing.Color.SkyBlue; 改第二处,这里要写成这样的格式            this.Controls.Add(pnl1);            this.ResumeLayout(false);        }#endregion    }}
改第二处

 

转载地址:http://ucykl.baihongyu.com/

你可能感兴趣的文章
delphi 把一个表的内容转到另一个表暂存时出错的解决方法。
查看>>
JavaScript 操作cookie
查看>>
BeanUtils.copyProperties() 用法
查看>>
微信公众平台开发 - 基础篇
查看>>
WinForm更新文件
查看>>
setprecision **fixed
查看>>
JVM系列五:JVM监测&工具[整理中]
查看>>
局部自适应自动色阶/对比度算法在图像增强上的应用。
查看>>
CMD命令
查看>>
Spring中@Autowired与@Resource的区别
查看>>
Python 学习笔记 -- 类和实例
查看>>
Android 静默安装/后台安装
查看>>
java 非空判断类
查看>>
【html5】如何让Canvas标签自适应设备
查看>>
SecureCRT最佳配色方法+直接修改默认配置方法 - imsoft.cnblogs
查看>>
通俗地介绍下---数据结构之堆
查看>>
JQuery实现简单的服务器轮询效果
查看>>
2017.6.26 工作记录
查看>>
“Too many open files” 小记
查看>>
tomcat报错
查看>>