开发者

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

开发者 https://www.devze.com 2022-12-30 16:35 出处:网络
I am creating an winform application that will run on a tablet PC.One form for this app will have a listview control.

I am creating an winform application that will run on a tablet PC. One form for this app will have a listview control.

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:

Based on suggestion from @GenericTeaType:

At the class level:

Stopwatch sw = new Stopwatch();

On the listview control:

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();                    
            }
       }


You could just show/hide a control for a certain period of time on the form MouseClick event.

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. If they then don't touch the control it'll change when the Timer ticks. Or, it will go away after the user has stopped tapping the +/- for x amount of milliseconds.

UPDATE for showing after 3 seconds.

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;
}


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.

Or possibly it would be safer to use some thing like Ctrl + + rather than just +.


I don't know for a Tablet PC, but would a FontDialog not do the job? 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消