小编a-f*_*f-a的帖子

ListView DrawColumnHeader 不起作用

我有以下方法来设置列表视图的列标题的背景颜色和字体,但它不起作用。有人可以帮助我吗?

private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
    using (StringFormat sf = new StringFormat())
    {
        // Store the column text alignment, letting it default
        // to Left if it has not been set to Center or Right.
        switch (e.Header.TextAlign)
        {
            case HorizontalAlignment.Center:
                sf.Alignment = StringAlignment.Center;
                break;
            case HorizontalAlignment.Right:
                sf.Alignment = StringAlignment.Far;
                break;
        }

        // Draw the standard header background.
        e.DrawBackground();

        // Draw the header text.
        using (Font headerFont = new Font("Helvetica", 25, FontStyle.Bold)) //Font size!!!!
        {
            e.Graphics.DrawString(e.Header.Text, headerFont, Brushes.Black, e.Bounds, …
Run Code Online (Sandbox Code Playgroud)

c# listview winforms

4
推荐指数
1
解决办法
3182
查看次数

C#Timer经过停止后仍然运行一点点

我正在使用Windows窗体.我在用System.Timers.Timer.虽然我停止了计时器timer.Stop(),但它仍然会更多.我放了一些bool变量来防止这个,但没有运气.有人知道吗?谢谢.

            timer = new System.Timers.Timer();
            timer.Elapsed += OnTimedEvent;
            timer.Interval = 1000;
            timer.start();

public void cancelConnectingSituation(Boolean result)
        {
            connecting = false;
            timer.Stop();
            if (result)
            {
                amountLabel.Text = "Connected";
            } 
            else
            {
                amountLabel.Text = "Connection fail";
            }
        }


private void OnTimedEvent(Object source, ElapsedEventArgs e)
        {
            if (device.position == 2 && connecting)
            {
                refreshTime();
                setConnectingText();
            }
            else if (connecting)
            {
                setConnectingText();
            }
            else
            {
                refreshTimeAndAmount();
            }
        }
Run Code Online (Sandbox Code Playgroud)

c# timer

1
推荐指数
1
解决办法
948
查看次数

标签 统计

c# ×2

listview ×1

timer ×1

winforms ×1