将颜色定义为静态变量 [英] Defining color as static variable
问题描述
您好。我想制作一个按钮,可以改变我的应用程序中所有背景网格的颜色。
我只知道这个函数改变了实际网格的颜色:
Hello. I would like to make a button which can change color of all background grids in my app.
I just know that this function changes color of actual grid:
LayoutRoot.Background = new SolidColorBrush(Colors.Blue);
现在,如何将此颜色值存储为静态值?我的意思是,点击后,颜色值将被存储。
如何在每个新页面加载时检索此值?
如何将此值存储在隔离存储中?
我知道我应该使用静态变量创建一个类。
我是编程的新手,所以有人可以告诉我如何编程页面,按钮将放在哪里和class.vb页面?
也许听起来很奇怪,但我根据例子了解一切。
Now, how to store this color value as a static value? I mean, after click, color value will be stored.
How to retrieve this value while every new page loads?
How can I store this value in isolated storage?
I know I should make a class with a static variable.
I am newbie in programming, so can someone tell me how to program page, where button will be placed and class.vb page?
Maybe it sounds weird, but I understand everything better basing on examples.
推荐答案
第一: - 使一个函数生成随机颜色
1st:-Make a function to generate random color
Private Function CreateRandomColor() As Color
Dim randonGen As New Random()
Dim randomColor As Color = Color.FromArgb(randonGen.[Next](255), randonGen.[Next](255), randonGen.[Next](255))
Return randomColor
End Function
Imports System.Windows.Media
Partial Public Class Settings
Inherits PhoneApplicationPage
Public Sub New()
InitializeComponent()
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
Dim color As Color
color= CreateRandomColor()
While (color != White or Red or Blue or Green) ''Specify color names u want
LayoutRoot.Background = New SolidColorBrush(color)
color = CreateRandomColor()
End While
End Sub
End Class
这篇关于将颜色定义为静态变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!