重写 Windows 窗体中的设置
我已在应用程序设置
中设置了表单文本
的名称,我需要重写
它。是否有可能,因为它向我显示它只是一个只读。
我知道我们可以使用 me.text=""
简单地更改它 但我的应用程序有一个问题,因为我有下面的代码,其中每次加载表单时都会删除文本。
Protected Overrides Sub OnLayout(ByVal e As System.Windows.Forms.LayoutEventArgs)
MyBase.OnLayout(e)
'Me.Text = CStr(Val(Me.Text) + 1)
FillList()
MyBase.OnLayout(e)
If FontColor.Items.Count = 0 Then
FontColor.Items.AddRange(Known_Color)
FontColor.MaxDropDownItems = 20
End If
MyBase.OnLayout(e)
If OutlineColor.Items.Count = 0 Then
OutlineColor.Items.AddRange(Known_Color)
OutlineColor.MaxDropDownItems = 20
End If
MyBase.OnLayout(e)
If BorderColor.Items.Count = 0 Then
BorderColor.Items.AddRange(Known_Color)
BorderColor.MaxDropDownItems = 20
End If
MyBase.OnLayout(e)
If BackgroundColor.Items.Count = 0 Then
BackgroundColor.Items.AddRange(Known_Color)
BackgroundColor.MaxDropDownItems = 20
End If
End Sub
有什么解决方法可以做到这一点吗?
I have set the name of my Form text
in the application settings
and I need to rewrite
it. Is it possible as it is showing me that it is only a readonly
.
I know that we can simply change it by using me.text=""
But I have a problem in my application as I have the below code where On every time the form loads it is erasing the text.
Protected Overrides Sub OnLayout(ByVal e As System.Windows.Forms.LayoutEventArgs)
MyBase.OnLayout(e)
'Me.Text = CStr(Val(Me.Text) + 1)
FillList()
MyBase.OnLayout(e)
If FontColor.Items.Count = 0 Then
FontColor.Items.AddRange(Known_Color)
FontColor.MaxDropDownItems = 20
End If
MyBase.OnLayout(e)
If OutlineColor.Items.Count = 0 Then
OutlineColor.Items.AddRange(Known_Color)
OutlineColor.MaxDropDownItems = 20
End If
MyBase.OnLayout(e)
If BorderColor.Items.Count = 0 Then
BorderColor.Items.AddRange(Known_Color)
BorderColor.MaxDropDownItems = 20
End If
MyBase.OnLayout(e)
If BackgroundColor.Items.Count = 0 Then
BackgroundColor.Items.AddRange(Known_Color)
BackgroundColor.MaxDropDownItems = 20
End If
End Sub
Is there any workaround to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这很可能就是你的错误所在。
您正在设置文本,然后调用基类
OnLayout
事件,这可能会导致文本恢复为默认值。如果您想更改某些内容,请在调用案例类事件处理程序后进行。如果您只是想更改表单的文本,为什么不直接使用 Form_Load 事件处理程序而不调用基本事件处理程序。
most probably this is where your mistake is.
You are setting the text and then you are calling the base class
OnLayout
event which is probably causing the text to get back to default value. If you want to change something do it after you call the case class event handler.If you are just trying to change the text of the form why not just use
Form_Load
event handler without calling the base event handler.回答有关应用程序设置中的表单文本为只读的问题。请查看此 MSDN 页面。
来自上面的链接:
简而言之,如果您的应用程序设置是应用程序范围的,则您无法在运行时更改它,您必须使用用户范围的设置或滚动您自己的存储。
编辑:添加到@Bojan 的答案。
OnLayout
事件将在InitializeComponent()
方法期间以及每次调整表单大小或更改控件大小时触发。我个人会将您的初始化移至Form_Load 事件
或New()
。IE
To answer your question about your Form Text in your application settings being readonly. Look at this MSDN Page.
From above Link:
In short if your application setting is application scoped you can not it change at runtime, you have to use a user scoped setting or roll your own storage.
Edit: to add to @Bojan 's answer. The
OnLayout
event will be fired during theInitializeComponent()
method and everytime you resize the form or change the size of a control. I would personally move your initialization to theForm_Load event
or toNew()
.i.e.