C#で2つのwinformを一緒に「リンク」できるかどうか疑問に思っていました。ApplicationProperties.ApplicationPort.BaudRate
呼び出したいすべてのインスタンスを作成する代わりに、次のように変数を呼び出すことができますか? VB.net に似ています。誰かが私を正しい方向に向けることができれば、それは非常に高く評価されます.
(MainBox) と (ApplicationProperties) の 2 つのフォームがあります。両方のフォームに互いにアクセスできるようにしたいと思います。VB.NET と同様の方法で。
元:
フォーム 1 にはシリアル ポート (ApplicationPort) があり、値を .xml ファイルに書き込んでいます。
public void SaveApplicationProperties()
{
try
{
//CreateNode(everything being referenced. Put text boxes, and drop down boxes here.
XmlTextWriter writer = new XmlTextWriter(@"C:\ForteSenderv2.0\Properties.xml", System.Text.Encoding.UTF8);
writer.WriteStartDocument(true);
//Making the code indeted by 2 characters.
writer.Formatting = Formatting.Indented;
writer.Indentation = 2;
//Making the start element "Table".
writer.WriteStartElement("Forte_Data_Gatherer_Application");
//Calling the rst of the .xml file to write.
CreateNode(ApplicationPort.PortName, ApplicationPort.BaudRate.ToString(), ApplicationPort.DataBits.ToString(), ApplicationPort.Parity.ToString(), ApplicationPort.StopBits.ToString(), ApplicationPort.Handshake.ToString(), writer);
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
MessageBox.Show(ApplicationPort.PortName);
MessageBox.Show(ApplicationPort.BaudRate.ToString());
}
catch (Exception ex)
{
MessageBox.Show("Writing to .xml file failure: " + ex.Message);
}
}
ここで、インスタンスを作成することなく、フォーム 2 からそのシリアル ポートを呼び出せるようにしたいと考えています。インスタンスで動作していますが、form2 で使用するシリアル ポート、テキスト ボックス、またはツールごとにインスタンスを作成するのは面倒です。VB.NET のように呼び出す方法はありますか?