简体   繁体   English

Winforms-如何允许用户使用隐藏控件增加ListView的字体大小?

[英]Winforms - How to allow user to increase font size of listview with hidden controls?

I am creating an winform application that will run on a tablet PC. 我正在创建一个将在平板电脑上运行的winform应用程序。 One form for this app will have a listview control. 此应用程序的一种形式将具有一个listview控件。

I would like to allow the user to change the font size based on preference (ie did they remember their glasses today). 我想允许用户根据喜好更改字体大小(即他们今天是否记得自己的眼镜)。 A few ways that I can think of would be a numeric-up-down or +/- button controls. 我能想到的几种方法是数字上-下或+/-按钮控件。 Both of these ways require screen real estate that is very limited. 这两种方式都要求屏幕空间非常有限。

Is there a control or technique that would allow font size changes with a hidden-when-not-used control? 是否有一种控件或技术允许使用隐藏的不使用的控件来更改字体大小?

UPDATE 1: 更新1:

Based on suggestion from @GenericTeaType : 根据@GenericTeaType的建议:

At the class level: 在课堂上:

Stopwatch sw = new Stopwatch();

On the listview control: 在listview控件上:

private void lst1_MouseDown(object sender, MouseEventArgs e)
    {
        //start stopwatch
        sw.Reset();
        sw.Start();
    }

private void lst1_MouseUp(object sender, MouseEventArgs e)
    {
        //stop stopwatch
        sw.Stop();
        //how long did stopwatch run for
        TimeSpan elapsedTime = sw.Elapsed;
        //show font change form if time exceeds 3 seconds
            if (elapsedTime.Seconds >= 3)
            {
                //show form - pass in current listview font size
                frmFontSizeChange ffsc = new frmFontSizeChange(slv.ReleaseFontSize);
                ffsc.ShowDialog();

                //refresh schedule with new font size
                populate_lst1();                    
            }
       }

Well you could just add a hidden control, but if you're not going to show it I don't think there's much point. 好吧,您可以只添加一个隐藏的控件,但是如果您不打算显示它,那么我认为没有什么意义。 Just handle the KeyPress or KeyDown event in the form and/or listview and if it's + or - make it bigger or smaller. 只需处理表单和/或列表视图中的KeyPressKeyDown事件,如果它是+或-使其更大或更小即可。

Or possibly it would be safer to use some thing like Ctrl + + rather than just + . 也许使用Ctrl + +类的东西而不是+会更安全。

You could just show/hide a control for a certain period of time on the form MouseClick event. 您可以在MouseClick事件表单上仅显示/隐藏控件一段时间。

For example: 例如:

public Form1()
{
    InitializeComponent();
    Timer1.Tick += new EventHandler(Timer1_Tick);
}

Timer Timer1;

private void Form1_MouseClick(object sender, MouseEventArgs e)
{
    // Will need handling to ensure it's not already displaying, etc... then:
    FontSizeControl.Show();
    Timer1.Enabled = true;
}

private void FontSizeControl_FontSizeChanged(object sender, EventArgs e)
{

    // Change the font size
    ...

    // Reset the timer
    Timer1.Enabled = false;
    Timer1.Enabled = true;

}

void Timer1_Tick(object sender, EventArgs e)
{
    FontSizeControl.Hide();
    Timer1.Enabled = false;
}

What this would basically do is to show the FontSize changing control that you've made (or will make) when the user taps the screen. 这基本上是要显示当用户点击屏幕时您已经(或将要制作)的FontSize更改控件。 If they then don't touch the control it'll change when the Timer ticks. 如果然后他们不触摸控件,它将在Timer时更改。 Or, it will go away after the user has stopped tapping the +/- for x amount of milliseconds. 或者,它将在用户停止点击+/- x毫秒后消失。

UPDATE for showing after 3 seconds. 3秒后显示更新

public Form1()
{
    InitializeComponent();
    Timer2.Tick += new EventHandler(Timer2_Tick);
    Timer2.Interval = 3000;
}

Timer Timer2;

private void Form1_MouseDown(object sender, MouseEventArgs e)
{
    Timer2.Enabled = true;
}

private void Form1_MouseUp(object sender, MouseEventArgs e)
{
    Timer2.Enabled = false;
}

void Timer2_Tick(object sender, EventArgs e)
{
    FontSizeControl.Show();
    Timer2.Enabled = false;
}

I don't know for a Tablet PC, but would a FontDialog not do the job? 我不了解Tablet PC,但是FontDialog不能完成这项工作吗? It is hidden when not used, and you might even instantiate it on a Button click, so ne resources are taken to make it live, etc. 当不使用它时,它是隐藏的,您甚至可以在单击按钮时实例化它,因此会占用大量资源以使其生效等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM