如何获得完美的边框,让窗户始终保持最佳状态?

时间:2016-08-22 12:06:43

标签: c# vb.net winforms

我有这个VB +WinForms申请。用户界面被捕获在下面的图像中

enter image description here

Add/Edit Material Window有自己独特的Aqua blue颜色边框。

背后的VB代码是

Option Strict Off
Option Explicit On
Friend Class FrmAddMaterial
    Inherits System.Windows.Forms.Form
    Friend ErrorFlag As ErrorFlagType
    Friend SavePath As String
    Public Event UpdateMaterialFile()

    Private Sub CmdAdd_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CmdAdd.Click
        Dim AddEditMat As New AddEditMaterialDialog
        With AddEditMat
            .TxtMaterialName.Text = ""
            .TxtWetRefractiveIndex.Text = ""
            .TxtDryRefractiveIndex.Text = ""
            .TxtLinearExpansion.Text = ""
            .TxtRadialExpansion.Text = ""
            .txtMDPrefix.Text = ""
            .TxtMaterialNumber.Text = Me.LstMaterials.Items.Count.ToString
            .Text = "Add Material"
            .SavePath = SavePath
            .Show()
        End With
        If LstMaterials.SelectedIndex > -1 Then
            UpdateMaterialScreen(Me, LstMaterials.SelectedIndex, ErrorFlag)
        Else
            UpdateMaterialScreen(Me, 0, ErrorFlag)
        End If
    End Sub

    Private Sub CmdEdit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CmdEdit.Click
        Dim MaterialData As MaterialType
        MaterialData = GetMaterialData(Me.LstMaterials.SelectedIndex, _
                                       SavePath, _
                                       ErrorFlag)
        Dim MatRef As New AddEditMaterialDialog
        With MatRef
            .TxtMaterialName.Text = MaterialData.MaterialName
            .TxtWetRefractiveIndex.Text = MaterialData.WetRefractiveIndex.ToString
            .TxtDryRefractiveIndex.Text = MaterialData.DryRefractiveIndex.ToString
            .TxtLinearExpansion.Text = MaterialData.LinearExpansion.ToString
            .TxtRadialExpansion.Text = MaterialData.RadiusExpansion.ToString
            .txtMDPrefix.Text = MaterialData.MDPrefix
            .TxtMaterialNumber.Text = MaterialData.Index.ToString
            .Text = "Edit Material"
            .SavePath = SavePath
            .Show()
        End With
    End Sub

    Private Sub CmdRemoveMaterial_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CmdRemoveMaterial.Click
        Dim Msg As String
        Dim MsgVal As Short
        Msg = "Are you sure that you want to remove this material?"
        MsgVal = MsgBox(Msg, MsgBoxStyle.YesNo, InfoMsg)
        If MsgVal = MsgBoxResult.Yes Then
            If LstMaterials.SelectedIndex <> -1 Then
                RemoveMaterialData(LstMaterials.SelectedIndex, _
                                   SavePath, _
                                   ErrorFlag)
                Me.LstMaterials.Items.RemoveAt((LstMaterials.SelectedIndex))
                If LstMaterials.Items.Count > 0 Then
                    LstMaterials.SelectedIndex = 0
                End If
                Call UpdateMaterialScreen(Me, LstMaterials.SelectedIndex, ErrorFlag)
            End If
        End If
    End Sub

    Private Sub FrmAddMaterial_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Enter
        If LstMaterials.SelectedIndex > -1 Then
            UpdateMaterialScreen(Me, LstMaterials.SelectedIndex, ErrorFlag)
        Else
            UpdateMaterialScreen(Me, 0, ErrorFlag)
        End If
    End Sub

    Private Sub FrmAddMaterial_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
        Me.Width = 278
        Me.Height = 289
        SavePath = System.IO.Path.Combine(ConfigSoftData.DirectoryData.AppPath, "Mold\lib")
    End Sub

    Private Sub LstMaterials_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles LstMaterials.SelectedIndexChanged
        Dim MaterialData As MaterialType
        MaterialData = GetMaterialData(LstMaterials.SelectedIndex, _
                                       SavePath, _
                                       ErrorFlag)
        With Me
            .TxtWetRefractiveIndex.Text = MaterialData.WetRefractiveIndex.ToString
            .TxtMDPrefix.Text = MaterialData.MDPrefix
        End With
    End Sub

    Private Sub FrmAddMaterial_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
        RaiseEvent UpdateMaterialFile()
    End Sub
End Class

我尝试将应用程序UI转换为C#并匹配VB表单中设置的所有属性,但我得到的是这样的

enter image description here

背后的C#代码是

using Microsoft.VisualBasic;
using Mold_Power_Suite.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Mold_Power_Suite.View
{
    public partial class FrmAddMaterial : Form
    {
        public FrmAddMaterial()
        {
            InitializeComponent();

            //FormClosed += FrmAddMaterial_FormClosed;
            //Load += FrmAddMaterial_Load;
            //Enter += FrmAddMaterial_Enter;
        }
        internal Mold_Power_Suite.Model.FrontEndStructures.ErrorFlagType ErrorFlag;
    internal string SavePath;
    public event UpdateMaterialFileEventHandler UpdateMaterialFile;
    public delegate void UpdateMaterialFileEventHandler();

    private void CmdAdd_Click(System.Object eventSender, System.EventArgs eventArgs)
    {
        AddEditMaterialDialog AddEditMat = new AddEditMaterialDialog();
        //var _with1 = AddEditMat;
        AddEditMat.TxtMaterialName.Text = "";
        AddEditMat.TxtWetRefractiveIndex.Text = "";
        AddEditMat.TxtDryRefractiveIndex.Text = "";
        AddEditMat.TxtLinearExpansion.Text = "";
        AddEditMat.TxtRadialExpansion.Text = "";
        AddEditMat.txtMDPrefix.Text = "";
        AddEditMat.TxtMaterialNumber.Text = this.LstMaterials.Items.Count.ToString();
        AddEditMat.Text = "Add Material";
        AddEditMat.SavePath = SavePath;
        AddEditMat.Show();
        if (LstMaterials.SelectedIndex > -1) {
            ModSoftOutput.UpdateMaterialScreen(this, LstMaterials.SelectedIndex,ref ErrorFlag);
        } else {
            ModSoftOutput.UpdateMaterialScreen(this, 0, ref ErrorFlag);
        }
    }

    private void CmdEdit_Click(System.Object eventSender, System.EventArgs eventArgs)
    {
        Mold_Power_Suite.Model.FrontEndStructures.MaterialType MaterialData = default(Mold_Power_Suite.Model.FrontEndStructures.MaterialType);

        short RIN=Convert.ToInt16( this.LstMaterials.SelectedIndex);
        MaterialData = ModSoftInputMod.GetMaterialData(ref RIN, ref SavePath, ref ErrorFlag);
        AddEditMaterialDialog MatRef = new AddEditMaterialDialog();
        //var _with2 = MatRef;
        MatRef.TxtMaterialName.Text = MaterialData.MaterialName;
        MatRef.TxtWetRefractiveIndex.Text = MaterialData.WetRefractiveIndex.ToString();
        MatRef.TxtDryRefractiveIndex.Text = MaterialData.DryRefractiveIndex.ToString();
        MatRef.TxtLinearExpansion.Text = MaterialData.LinearExpansion.ToString();
        MatRef.TxtRadialExpansion.Text = MaterialData.RadiusExpansion.ToString();
        MatRef.txtMDPrefix.Text = MaterialData.MDPrefix;
        MatRef.TxtMaterialNumber.Text = MaterialData.Index.ToString();
        MatRef.Text = "Edit Material";
        MatRef.SavePath = SavePath;
        MatRef.Show();
    }

    private void CmdRemoveMaterial_Click(System.Object eventSender, System.EventArgs eventArgs)
    {
    string Msg = null;
        //short MsgVal = 0; // Commented this line and made MsgVal as var
        Msg = "Are you sure that you want to remove this material?";
        var MsgVal = Interaction.MsgBox(Msg, MsgBoxStyle.YesNo,ModSoftFrontEndGlobalVariables. InfoMsg);
        if (MsgVal == MsgBoxResult.Yes) 
        {
            if (LstMaterials.SelectedIndex != -1)
            {
                short value = Convert.ToInt16((LstMaterials.SelectedIndex));
               ModSoftOutput. RemoveMaterialData(ref value, SavePath,ref  ErrorFlag);
                this.LstMaterials.Items.RemoveAt((LstMaterials.SelectedIndex));
                if (LstMaterials.Items.Count > 0) {
                    LstMaterials.SelectedIndex = 0;
                }
                ModSoftOutput.UpdateMaterialScreen(this, LstMaterials.SelectedIndex,ref ErrorFlag);
            }
        }
    }

        //This event is not being fired up . The code below has been pasted into FrmAddMaterial_Load()
    private void FrmAddMaterial_Enter(object sender, System.EventArgs e)
    {
        if (LstMaterials.SelectedIndex > -1) {
            ModSoftOutput.UpdateMaterialScreen(this, LstMaterials.SelectedIndex,ref ErrorFlag);
        } else {
            ModSoftOutput.UpdateMaterialScreen(this, 0,ref ErrorFlag);
        }
    }

    private void FrmAddMaterial_Load(System.Object eventSender, System.EventArgs eventArgs)
    {
        this.Width = 278;
        this.Height = 289;
        SavePath = System.IO.Path.Combine(ModSoftFrontEndGlobalVariables.ConfigSoftData.DirectoryData.AppPath, "Mold\\lib");

        /*if (LstMaterials.SelectedIndex > -1)
        {
            ModSoftOutput.UpdateMaterialScreen(this, LstMaterials.SelectedIndex, ref ErrorFlag);
        }
        else
        {
            ModSoftOutput.UpdateMaterialScreen(this, 0, ref ErrorFlag);
        }*/
    }

    private void LstMaterials_SelectedIndexChanged(System.Object eventSender, System.EventArgs eventArgs)
    {
        Mold_Power_Suite.Model.FrontEndStructures.MaterialType MaterialData = default(Mold_Power_Suite.Model.FrontEndStructures.MaterialType);
        short RINumber= Convert.ToInt16(LstMaterials.SelectedIndex);
        MaterialData = ModSoftInputMod.GetMaterialData(ref RINumber,ref SavePath,ref ErrorFlag);
       // var _with3 = this;
        this.TxtWetRefractiveIndex.Text = MaterialData.WetRefractiveIndex.ToString();
        this.TxtMDPrefix.Text = MaterialData.MDPrefix;
    }

    private void FrmAddMaterial_FormClosed(object sender, FormClosedEventArgs e)
    {
        if (UpdateMaterialFile != null) {
            UpdateMaterialFile();
        }
    }


    }
}

我确保在C#代码

Program.cs文件中添加这些行
static  class Program
    {
      [STAThread]
      static void Main()
      {
          Application.EnableVisualStyles();
          Application.SetCompatibleTextRenderingDefault(false);
          Mold_Power_Suite.View.frmMain mainForm = new frmMain();
         // WindowsFormsApplication3.view.Form1 abc = new view.Form1();
          Application.Run(mainForm);
      }
    }

以下是Designer.cs

namespace Mold_Power_Suite.View
{
    partial class FrmAddMaterial
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.ToolTip1 = new System.Windows.Forms.ToolTip(this.components);
            this.TxtMDPrefix = new System.Windows.Forms.TextBox();
            this.CmdRemoveMaterial = new System.Windows.Forms.Button();
            this.CmdReturn = new System.Windows.Forms.Button();
            this.CmdEdit = new System.Windows.Forms.Button();
            this.CmdAdd = new System.Windows.Forms.Button();
            this.TxtWetRefractiveIndex = new System.Windows.Forms.TextBox();
            this.LstMaterials = new System.Windows.Forms.ListBox();
            this.Label2 = new System.Windows.Forms.Label();
            this.Label1 = new System.Windows.Forms.Label();
            this.toolTip2 = new System.Windows.Forms.ToolTip(this.components);
            this.SuspendLayout();
            // 
            // TxtMDPrefix
            // 
            this.TxtMDPrefix.AcceptsReturn = true;
            this.TxtMDPrefix.BackColor = System.Drawing.SystemColors.Window;
            this.TxtMDPrefix.Cursor = System.Windows.Forms.Cursors.IBeam;
            this.TxtMDPrefix.Enabled = false;
            this.TxtMDPrefix.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.TxtMDPrefix.ForeColor = System.Drawing.SystemColors.WindowText;
            this.TxtMDPrefix.Location = new System.Drawing.Point(152, 80);
            this.TxtMDPrefix.MaxLength = 0;
            this.TxtMDPrefix.Name = "TxtMDPrefix";
            this.TxtMDPrefix.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.TxtMDPrefix.Size = new System.Drawing.Size(105, 20);
            this.TxtMDPrefix.TabIndex = 2;
            // 
            // CmdRemoveMaterial
            // 
            this.CmdRemoveMaterial.BackColor = System.Drawing.SystemColors.Control;
            this.CmdRemoveMaterial.Cursor = System.Windows.Forms.Cursors.Default;
            this.CmdRemoveMaterial.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.CmdRemoveMaterial.ForeColor = System.Drawing.SystemColors.ControlText;
            this.CmdRemoveMaterial.Location = new System.Drawing.Point(152, 219);
            this.CmdRemoveMaterial.Name = "CmdRemoveMaterial";
            this.CmdRemoveMaterial.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.CmdRemoveMaterial.Size = new System.Drawing.Size(105, 25);
            this.CmdRemoveMaterial.TabIndex = 5;
            this.CmdRemoveMaterial.Text = "&Remove Material";
            this.CmdRemoveMaterial.UseVisualStyleBackColor = false;
            this.CmdRemoveMaterial.Click += new System.EventHandler(this.CmdRemoveMaterial_Click);
            // 
            // CmdReturn
            // 
            this.CmdReturn.BackColor = System.Drawing.SystemColors.Control;
            this.CmdReturn.Cursor = System.Windows.Forms.Cursors.Default;
            this.CmdReturn.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.CmdReturn.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.CmdReturn.ForeColor = System.Drawing.SystemColors.ControlText;
            this.CmdReturn.Location = new System.Drawing.Point(89, 291);
            this.CmdReturn.Name = "CmdReturn";
            this.CmdReturn.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.CmdReturn.Size = new System.Drawing.Size(105, 25);
            this.CmdReturn.TabIndex = 15;
            this.CmdReturn.Text = "&Close";
            this.CmdReturn.UseVisualStyleBackColor = false;
            // 
            // CmdEdit
            // 
            this.CmdEdit.BackColor = System.Drawing.SystemColors.Control;
            this.CmdEdit.Cursor = System.Windows.Forms.Cursors.Default;
            this.CmdEdit.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.CmdEdit.ForeColor = System.Drawing.SystemColors.ControlText;
            this.CmdEdit.Location = new System.Drawing.Point(152, 187);
            this.CmdEdit.Name = "CmdEdit";
            this.CmdEdit.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.CmdEdit.Size = new System.Drawing.Size(105, 25);
            this.CmdEdit.TabIndex = 4;
            this.CmdEdit.Text = "&Edit Material";
            this.CmdEdit.UseVisualStyleBackColor = false;
            this.CmdEdit.Click += new System.EventHandler(this.CmdEdit_Click);
            // 
            // CmdAdd
            // 
            this.CmdAdd.BackColor = System.Drawing.SystemColors.Control;
            this.CmdAdd.Cursor = System.Windows.Forms.Cursors.Default;
            this.CmdAdd.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.CmdAdd.ForeColor = System.Drawing.SystemColors.ControlText;
            this.CmdAdd.Location = new System.Drawing.Point(152, 155);
            this.CmdAdd.Name = "CmdAdd";
            this.CmdAdd.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.CmdAdd.Size = new System.Drawing.Size(105, 25);
            this.CmdAdd.TabIndex = 3;
            this.CmdAdd.Text = "&Add Material";
            this.CmdAdd.UseVisualStyleBackColor = false;
            this.CmdAdd.Click += new System.EventHandler(this.CmdAdd_Click);
            // 
            // TxtWetRefractiveIndex
            // 
            this.TxtWetRefractiveIndex.AcceptsReturn = true;
            this.TxtWetRefractiveIndex.BackColor = System.Drawing.SystemColors.Window;
            this.TxtWetRefractiveIndex.Cursor = System.Windows.Forms.Cursors.IBeam;
            this.TxtWetRefractiveIndex.Enabled = false;
            this.TxtWetRefractiveIndex.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.TxtWetRefractiveIndex.ForeColor = System.Drawing.SystemColors.WindowText;
            this.TxtWetRefractiveIndex.Location = new System.Drawing.Point(152, 32);
            this.TxtWetRefractiveIndex.MaxLength = 0;
            this.TxtWetRefractiveIndex.Name = "TxtWetRefractiveIndex";
            this.TxtWetRefractiveIndex.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.TxtWetRefractiveIndex.Size = new System.Drawing.Size(105, 20);
            this.TxtWetRefractiveIndex.TabIndex = 1;
            // 
            // LstMaterials
            // 
            this.LstMaterials.BackColor = System.Drawing.SystemColors.Window;
            this.LstMaterials.Cursor = System.Windows.Forms.Cursors.Default;
            this.LstMaterials.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.LstMaterials.ForeColor = System.Drawing.SystemColors.WindowText;
            this.LstMaterials.ItemHeight = 14;
            this.LstMaterials.Location = new System.Drawing.Point(16, 16);
            this.LstMaterials.Name = "LstMaterials";
            this.LstMaterials.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.LstMaterials.Size = new System.Drawing.Size(121, 228);
            this.LstMaterials.TabIndex = 0;
            this.LstMaterials.SelectedIndexChanged += new System.EventHandler(this.LstMaterials_SelectedIndexChanged);
            // 
            // Label2
            // 
            this.Label2.BackColor = System.Drawing.SystemColors.Control;
            this.Label2.Cursor = System.Windows.Forms.Cursors.Default;
            this.Label2.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Label2.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Label2.Location = new System.Drawing.Point(152, 64);
            this.Label2.Name = "Label2";
            this.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label2.Size = new System.Drawing.Size(81, 17);
            this.Label2.TabIndex = 8;
            this.Label2.Text = "Data File Prefix";
            // 
            // Label1
            // 
            this.Label1.BackColor = System.Drawing.SystemColors.Control;
            this.Label1.Cursor = System.Windows.Forms.Cursors.Default;
            this.Label1.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Label1.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Label1.Location = new System.Drawing.Point(152, 16);
            this.Label1.Name = "Label1";
            this.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label1.Size = new System.Drawing.Size(105, 17);
            this.Label1.TabIndex = 7;
            this.Label1.Text = "Wet Refractive Index";
            // 
            // FrmAddMaterial
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 19F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.CancelButton = this.CmdReturn;
            this.ClientSize = new System.Drawing.Size(272, 255);
            this.Controls.Add(this.TxtMDPrefix);
            this.Controls.Add(this.CmdRemoveMaterial);
            this.Controls.Add(this.CmdReturn);
            this.Controls.Add(this.CmdEdit);
            this.Controls.Add(this.CmdAdd);
            this.Controls.Add(this.TxtWetRefractiveIndex);
            this.Controls.Add(this.LstMaterials);
            this.Controls.Add(this.Label2);
            this.Controls.Add(this.Label1);
            this.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
            this.Location = new System.Drawing.Point(3, 14);
            this.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4);
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "FrmAddMaterial";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.WindowsDefaultBounds;
            this.Text = " Add/Edit Material";
            this.Activated += new System.EventHandler(this.FrmAddMaterial_Enter);
            this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.FrmAddMaterial_FormClosed);
            this.Load += new System.EventHandler(this.FrmAddMaterial_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        public System.Windows.Forms.ToolTip ToolTip1;
        public System.Windows.Forms.TextBox TxtMDPrefix;
        public System.Windows.Forms.Button CmdRemoveMaterial;
        public System.Windows.Forms.Button CmdReturn;
        public System.Windows.Forms.Button CmdEdit;
        public System.Windows.Forms.Button CmdAdd;
        public System.Windows.Forms.TextBox TxtWetRefractiveIndex;
        public System.Windows.Forms.ListBox LstMaterials;
        public System.Windows.Forms.Label Label2;
        public System.Windows.Forms.Label Label1;
        public System.Windows.Forms.ToolTip toolTip2;

    }
}
  1. 如何使应用程序和所有相应的弹出窗口看起来与它们在VB中的外观完全相同?
  2. 当Windows不活跃时,往往会落后于应用程序。我希望他们不要超越Parent Window.
  3. 我该如何解决这些问题?

1 个答案:

答案 0 :(得分:1)

而不是

MatRef.Show();

MatRef.ShowDialog();

如果这不起作用,那么在此之前再添加一行

MatRef.TopLevel = false;

示例代码:

ParentForm.Designer.cs

namespace MyPro
{
partial class ParentForm
{
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.button1 = new System.Windows.Forms.Button();
        this.SuspendLayout();
        // 
        // button1
        // 
        this.button1.Location = new System.Drawing.Point(231, 193);
        this.button1.Name = "button1";
        this.button1.Size = new System.Drawing.Size(103, 44);
        this.button1.TabIndex = 0;
        this.button1.Text = "Show Dialog";
        this.button1.UseVisualStyleBackColor = true;
        this.button1.Click += new System.EventHandler(this.button1_Click);
        // 
        // ParentForm
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(1059, 719);
        this.Controls.Add(this.button1);
        this.Name = "ParentForm";
        this.Text = "Parent Form";
        this.ResumeLayout(false);

    }

    #endregion

    private System.Windows.Forms.Button button1;
}
}

ParentForm.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyPro
{
public partial class ParentForm : Form
{
    public ParentForm()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Form f = new DialogWindow();
        f.StartPosition = FormStartPosition.CenterScreen;
        f.ShowDialog();
    }
}
}

DialogWindow.Designer.cs

namespace MyPro
{
partial class DialogWindow
{
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.SuspendLayout();
        // 
        // DialogWindow
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(282, 255);
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
        this.Name = "DialogWindow";
        this.Text = "DialogWindow";
        this.ResumeLayout(false);

    }

    #endregion
}
}

enter image description here