保存我的winform应用程序用户所做的更改 [英] save changes that the user of my winform app has done

查看:61
本文介绍了保存我的winform应用程序用户所做的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好:我的winform中的
,用户可以在文本框中写入更改字体样式和颜色。但我面临一个小问题,我需要你的帮助。

当用户完成所有样式更改的文本后,他会在另一个文本框中写入,他所做的更改第二个文本在第一个文本中获得,因为第一个更改未保存。我怎么能保存它们?

提前感谢您的帮助:)

解决方案

my目标是让用户在运行时能够更改一个文本框的颜色/字体设置,并仅保存此文本框的更改。

对于这样一个简单,有限的要求,我会使用应用程序。设置类,用于存储重新打开应用程序时恢复颜色/字体设置所需的信息。



1.在Visual Studio Solutions Explorer中双击属性/Settings.Settings



2.在设置设计器中创建属性:[ ^ ]:



TBFont类型字体

TBText类型字符串

TBBackColor类型颜色

TBForeColor类型颜色



3.在您的密码中:



a。在Application / MainForm初始化时读取和刷新属性:

  public  Form1()
{
InitializeComponent() ;

if (Settings.Default.Properties [ TBFont]!= null
{
YourTextBox.Text = Settings.Default.TBText;
YourTextBox.Font = Settings.Default.TBFont;
YourTextBox.BackColor = Settings.Default.TBBackColor;
YourTextBox.ForeColor = Settings.Default.TBForeColor;
}
}

b。需要时保存/更新属性:

  private   void  btnRefreshAndSaveSettings_Click(  object  sender,EventArgs e)
{
Settings.Default.TBText = YourTextBox.Text;
Settings.Default.TBFont = YourTextBox.Font;
Settings.Default.TBBackColor = YourTextBox.BackColor;
Settings.Default.TBForeColor = YourTextBox.ForeColor;
Settings.Default.Save();
}


我真的相信你不知道 TextChanged 的事件文本框。当Text属性发生更改时会引发此事件,在.NET应用程序中也是这些输入字段的Value属性。您可以处理该事件,并在继续处理下一个TextBox之前将Text保存在TextBox中。



要了解有关此活动的更多信息,请阅读此MSDN文档 [ ^ ]。

hello :D
in my winform , the user is able to write in a textbox change the font style and the color. But I'm facing a little problem and I need your help in it.
when the user finishes his text with all the style changes and he go to write in another textbox , the changes that he make in the second text procure in the first because the first changes are not saved. how can I save them?
thank you in advance for your help :)

解决方案

"my goal is to let the user able to change the color/font settings for one textbox while running and save the changes for only this textbox."

For such a simple, limited, requirement I would use the Application.Settings class to store information needed to restore the color/font settings when the Application is re-opened.

1. In the Visual Studio Solutions Explorer double-click on Properties/Settings.Settings

2. In the Settings Designer create properties: [^]:

TBFont type Font
TBText type string
TBBackColor type Color
TBForeColor type Color

3. In your code:

a. read and refresh the Properties when the Application/MainForm initializes:

public Form1()
{
    InitializeComponent();

    if(Settings.Default.Properties["TBFont"] != null)
    {
        YourTextBox.Text = Settings.Default.TBText;
        YourTextBox.Font = Settings.Default.TBFont;
        YourTextBox.BackColor = Settings.Default.TBBackColor;
        YourTextBox.ForeColor = Settings.Default.TBForeColor;
    }
}

b. save/update the Properties when you need to:

private void btnRefreshAndSaveSettings_Click(object sender, EventArgs e)
{
    Settings.Default.TBText = YourTextBox.Text;
    Settings.Default.TBFont = YourTextBox.Font;
    Settings.Default.TBBackColor = YourTextBox.BackColor;
    Settings.Default.TBForeColor = YourTextBox.ForeColor;
    Settings.Default.Save();
} 


I really believe that you're unaware of the TextChanged event of the TextBox. This event is raised when there is a change in the Text property, which in .NET application is also the Value property for these input fields. You can handle the event, and save the Text inside the TextBox before he can continue working on the next TextBox.

To learn more on this event, please read this MSDN document[^].


这篇关于保存我的winform应用程序用户所做的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆