• 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 = 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
      end
    end
    //------------
    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
      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(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
    
        }
    }
    改第二处
  • 相关阅读:
    failed to push some refs to 'git@github.com:laniu/liuna.git'报错原因
    ECMAScript和JavaScript的关系
    js面试总结
    第16章 脚本化css
    代理模式
    SQL
    VS
    Js/Jquery获取iframe中的元素 在Iframe中获取父窗体的元素方法
    SQL
    C#
  • 原文地址:https://www.cnblogs.com/rogge7/p/5747569.html
Copyright © 2020-2023  润新知