Форум программистов, компьютерный форум, киберфорум
C# Windows Forms
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.86/29: Рейтинг темы: голосов - 29, средняя оценка - 4.86
-28 / 6 / 1
Регистрация: 13.12.2015
Сообщений: 398
1

Мигание кнопки красным цветом

22.07.2017, 14:35. Показов 5837. Ответов 10
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Всем добрый день. На фоне формы размещена картинка (вложение). На картинке , поверх нее, должна быть круглая красная кнопка, которая мигает. Но когда ставлю, чтобы кнопка быть красным цветом, картинка пропадает, т.к. кнопка поверх картинки.
мигание задал след образом- ошибка, не указан using для DispatcherTimer
C#
1
2
3
4
5
6
7
8
9
10
11
12
button1.BackColor = Color.Green;
 
var dt = new DispatcherTimer();
 
dt.Interval = TimeSpan.FromMilliseconds(500);
dt.Tick += delegate
{
    button1.BackColor = Color.Transparent;
    dt.Stop();
};
 
dt.Start();
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Timers;
 
namespace WindowsFormsApplication1
{
    public partial class Form7 : Form
    {
        public Form7()
        {
            InitializeComponent();
         
        }
 
        private void Form7_Paint(object sender, PaintEventArgs e)
        {
 
            System.Drawing.Drawing2D.GraphicsPath Button_Path = new System.Drawing.Drawing2D.GraphicsPath();
            Button_Path.AddEllipse(0, 0, this.button1.Width, this.button1.Height);
            Region Button_Region = new Region(Button_Path);
            this.button1.Region = Button_Region;
 
 
            button1.BackColor = System.Drawing.Color.Red;
 
           
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
           
        }
    }
}
Миниатюры
Мигание кнопки красным цветом  
0
Лучшие ответы (1)
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
22.07.2017, 14:35
Ответы с готовыми решениями:

Как лучше проследить за красным цветом в BITMAP?
Подскажите пожалуйста, такая задача: Камера снимает монитор. Есть Скриншот_Монитора и...

Подсчитать количество строк в datagridview, выделенных красным цветом
В датагриде строки красятся с помощью такого кода: private void PaintRows() { ...

Как сделать так чтобы, при нажатии на кнопку половина диалогового окна закрашивалась красным цветом?
Как сделать так чтобы, при нажатии на кнопку половина диалогового окна закрашивалась красным цветом?

Сделать полужирным цветом текст в ToolTipText кнопки
Добрый вечер! Подскажите, как можно сделать в ToolTipText кнопки текст сделать полужирным????

10
8940 / 4852 / 1886
Регистрация: 11.02.2013
Сообщений: 10,246
22.07.2017, 16:20 2
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
public class BlinkButton : Button
{
    private Timers.Timer _timer;
    private readonly Action _blinkAction;
    private bool _blink;
 
    public BlinkButton()
    {
        _blinkAction = new Action(() =>
        {
            BackColor = _blink ? Color.Transparent : Color.Red;
            _blink = !_blink;
        });
        _timer = new Timers.Timer(500);
        _timer.Elapsed += _timer_Elapsed;
    }
        
    private void _timer_Elapsed(object sender, Timers.ElapsedEventArgs e)
    {
        _blinkAction();
    }
 
    public void Start()
    {
        _timer.Start();
    }
 
    public void Stop()
    {
        _timer.Stop();
    }
 
    protected override void OnHandleCreated(EventArgs e)
    {
        base.OnHandleCreated(e);
        OnSizeChanged(e);
    }
 
    protected override void OnSizeChanged(EventArgs e)
    {
        base.OnSizeChanged(e);
        using (var path = new GraphicsPath())
        {
            var rect = ClientRectangle;
            rect.Inflate(-Padding.Left - Padding.Right - 5, -Padding.Top - Padding.Bottom - 5);
            var pt = new PointF(rect.X + rect.Width / 2f, rect.Y + rect.Height / 2f);
            var r = Math.Min(rect.Height, rect.Width) / 2;
            var rectf = new RectangleF(pt.X - r, pt.Y - r, r * 2, r * 2);
            path.AddEllipse(rectf);
            Region = new Region(path);
        }
    }
}
0
-28 / 6 / 1
Регистрация: 13.12.2015
Сообщений: 398
22.07.2017, 21:35  [ТС] 3
ViterAlex, спасибо большое. Скажите пожалуйста, а что добавить в using ?
using System.Timers;:??
0
8940 / 4852 / 1886
Регистрация: 11.02.2013
Сообщений: 10,246
22.07.2017, 22:05 4
C#
1
using System;
0
-28 / 6 / 1
Регистрация: 13.12.2015
Сообщений: 398
22.07.2017, 22:51  [ТС] 5
ViterAlex, так оно у меня есть. Пришет прощена директива
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
 
 
namespace WindowsFormsApplication1
{
 
    public class BlinkButton : Button
    {
        private Timers.Timer _timer;
        private readonly Action _blinkAction;
        private bool _blink;
 
        public BlinkButton()
        {
            _blinkAction = new Action(() =>
            {
                BackColor = _blink ? Color.Transparent : Color.Red;
                _blink = !_blink;
            });
            _timer = new Timers.Timer(500);
            _timer.Elapsed += _timer_Elapsed;
        }
 
        private void _timer_Elapsed(object sender, Timers.ElapsedEventArgs e)
        {
            _blinkAction();
        }
 
        public void Start()
        {
            _timer.Start();
        }
 
        public void Stop()
        {
            _timer.Stop();
        }
 
        protected override void OnHandleCreated(EventArgs e)
        {
            base.OnHandleCreated(e);
            OnSizeChanged(e);
        }
 
        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);
            using (var path = new GraphicsPath())
            {
                var rect = ClientRectangle;
                rect.Inflate(-Padding.Left - Padding.Right - 5, -Padding.Top - Padding.Bottom - 5);
                var pt = new PointF(rect.X + rect.Width / 2f, rect.Y + rect.Height / 2f);
                var r = Math.Min(rect.Height, rect.Width) / 2;
                var rectf = new RectangleF(pt.X - r, pt.Y - r, r * 2, r * 2);
                path.AddEllipse(rectf);
                Region = new Region(path);
            }
        }
    }
 
    public partial class Form7 : Form
    {
        public Form7()
        {
            InitializeComponent();
         
        }
 
        private void Form7_Paint(object sender, PaintEventArgs e)
        {
 
            System.Drawing.Drawing2D.GraphicsPath Button_Path = new System.Drawing.Drawing2D.GraphicsPath();
            Button_Path.AddEllipse(0, 0, this.button1.Width, this.button1.Height);
            Region Button_Region = new Region(Button_Path);
            this.button1.Region = Button_Region;
 
 
         
 
           
           
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            button1.BackColor = System.Drawing.Color.Red;
            button2.BackColor = System.Drawing.Color.Red;
            button3.BackColor = System.Drawing.Color.Red;
            button4.BackColor = System.Drawing.Color.Red;
            button5.BackColor = System.Drawing.Color.Red;
            button6.BackColor = System.Drawing.Color.Red;
            button7.BackColor = System.Drawing.Color.Red;
            button8.BackColor = System.Drawing.Color.Red;
 
        }
 
       
 
        private void button9_Click(object sender, EventArgs e)
        {
           button1.BackColor = System.Drawing.Color.Red;
            button2.BackColor = System.Drawing.Color.Red;
            button3.BackColor = System.Drawing.Color.Red;
            button4.BackColor = System.Drawing.Color.Red;
            button5.BackColor = System.Drawing.Color.Red;
            button6.BackColor = System.Drawing.Color.Red;
            button7.BackColor = System.Drawing.Color.Red;
            button8.BackColor = System.Drawing.Color.Red;
        }
 
        private void button10_Click(object sender, EventArgs e)
        {
            button1.BackColor = System.Drawing.Color.Black;
            button2.BackColor = System.Drawing.Color.Black;
            button3.BackColor = System.Drawing.Color.Black;
            button4.BackColor = System.Drawing.Color.Black;
            button5.BackColor = System.Drawing.Color.Black;
            button6.BackColor = System.Drawing.Color.Black;
            button7.BackColor = System.Drawing.Color.Black;
            button8.BackColor = System.Drawing.Color.Black;
        }
 
        private void pictureBox1_Click(object sender, EventArgs e)
        {
 
        }
 
        private void button5_Click(object sender, EventArgs e)
        {
            {
                Form8 f = new Form8();
                f.Hide();
                f.Show();
            }
        }
    }
}
0
8940 / 4852 / 1886
Регистрация: 11.02.2013
Сообщений: 10,246
22.07.2017, 23:16 6
Добавь
C#
1
2
using System.Timers;
using Timer = System.Timers.Timer;
И убери в коде Timers. Так будет проще
0
-28 / 6 / 1
Регистрация: 13.12.2015
Сообщений: 398
22.07.2017, 23:35  [ТС] 7
ViterAlex, тишина

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Timers;
using Timer = System.Timers.Timer;
using System.Drawing.Drawing2D;
 
 
 
 
namespace WindowsFormsApplication1
{
 
        public partial class Form7 : Form
    {
 
 
            public class BlinkButton : Button
            {
                private Timer _timer;
                private readonly Action _blinkAction;
                private bool _blink;
 
                public BlinkButton()
                {
                    _blinkAction = new Action(() =>
                    {
                        BackColor = _blink ? Color.Transparent : Color.Red;
                        _blink = !_blink;
                    });
                    _timer = new Timer(500);
                    _timer.Elapsed += _timer_Elapsed;
                }
 
                private void _timer_Elapsed(object sender, ElapsedEventArgs e)
                {
                    _blinkAction();
                }
 
                public void Start()
                {
                    _timer.Start();
                }
 
                public void Stop()
                {
                    _timer.Stop();
                }
 
                protected override void OnHandleCreated(EventArgs e)
                {
                    base.OnHandleCreated(e);
                    OnSizeChanged(e);
                }
 
                protected override void OnSizeChanged(EventArgs e)
                {
                    base.OnSizeChanged(e);
                    using (var path = new GraphicsPath())
                    {
                        var rect = ClientRectangle;
                        rect.Inflate(-Padding.Left - Padding.Right - 5, -Padding.Top - Padding.Bottom - 5);
                        var pt = new PointF(rect.X + rect.Width / 2f, rect.Y + rect.Height / 2f);
                        var r = Math.Min(rect.Height, rect.Width) / 2;
                        var rectf = new RectangleF(pt.X - r, pt.Y - r, r * 2, r * 2);
                        path.AddEllipse(rectf);
                        Region = new Region(path);
                    }
                }
            }
        public Form7()
        {
            InitializeComponent();
         
        }
 
      private void Form7_Paint(object sender, PaintEventArgs e)
        {
 
            System.Drawing.Drawing2D.GraphicsPath Button_Path = new System.Drawing.Drawing2D.GraphicsPath();
            Button_Path.AddEllipse(0, 0, this.button1.Width, this.button1.Height);
            Region Button_Region = new Region(Button_Path);
            this.button1.Region = Button_Region;
 
 
         
 
           
           
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            button1.BackColor = System.Drawing.Color.Red;
            button2.BackColor = System.Drawing.Color.Red;
            button3.BackColor = System.Drawing.Color.Red;
            button4.BackColor = System.Drawing.Color.Red;
            button5.BackColor = System.Drawing.Color.Red;
            button6.BackColor = System.Drawing.Color.Red;
            button7.BackColor = System.Drawing.Color.Red;
            button8.BackColor = System.Drawing.Color.Red;
 
        }
 
       
 
        private void button9_Click(object sender, EventArgs e)
        {
           button1.BackColor = System.Drawing.Color.Red;
            button2.BackColor = System.Drawing.Color.Red;
            button3.BackColor = System.Drawing.Color.Red;
            button4.BackColor = System.Drawing.Color.Red;
            button5.BackColor = System.Drawing.Color.Red;
            button6.BackColor = System.Drawing.Color.Red;
            button7.BackColor = System.Drawing.Color.Red;
            button8.BackColor = System.Drawing.Color.Red;
        }
 
        private void button10_Click(object sender, EventArgs e)
        {
            button1.BackColor = System.Drawing.Color.Black;
            button2.BackColor = System.Drawing.Color.Black;
            button3.BackColor = System.Drawing.Color.Black;
            button4.BackColor = System.Drawing.Color.Black;
            button5.BackColor = System.Drawing.Color.Black;
            button6.BackColor = System.Drawing.Color.Black;
            button7.BackColor = System.Drawing.Color.Black;
            button8.BackColor = System.Drawing.Color.Black;
        }
 
        private void pictureBox1_Click(object sender, EventArgs e)
        {
 
        }
 
        private void button5_Click(object sender, EventArgs e)
        {
            {
                Form8 f = new Form8();
                f.Hide();
                f.Show();
            }
        }
    }
}
0
8940 / 4852 / 1886
Регистрация: 11.02.2013
Сообщений: 10,246
22.07.2017, 23:38 8
studentrm, а что должно происходить, по-твоему?
1
-28 / 6 / 1
Регистрация: 13.12.2015
Сообщений: 398
22.07.2017, 23:45  [ТС] 9
ViterAlex, мигать кнопки красным цветом
0
8940 / 4852 / 1886
Регистрация: 11.02.2013
Сообщений: 10,246
23.07.2017, 00:07 10
Лучший ответ Сообщение было отмечено studentrm как решение

Решение

studentrm, я не комментировал свой код, т.к. он достаточно очевиден. Но, видимо, придётся.
Класс BlinkButton — это обычная кнопка, которую я дополнил таймером и методами Start/Stop для работы с ним. Тебе нужно все свои кнопки на форме заменить на BlinkButton и тогда, вызывая метод Start у этих кнопок ты включишь мигание.
1
-28 / 6 / 1
Регистрация: 13.12.2015
Сообщений: 398
23.07.2017, 00:14  [ТС] 11
ViterAlex, ViterAlex, переименовать их в BlinkButton1 вместо ButtonClick
0
23.07.2017, 00:14
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
23.07.2017, 00:14
Помогаю со студенческими работами здесь

Отображение дат в MonthCalendar из DataTable красным цветом
У меня есть таблица со списком дат. Как сделать, чтобы этот список выделялся красным или каким-либо...

Мигание 3 лампочек,по нажатии кнопки выключается...
Задание состоит в том что Лампочки мигают хаотично...при нажатии на кнопку они гаснут,и при этом...

В NetBeans в JTable1 закрасить одну ячейку красным цветом по нажатию кнопки
Срочно надо!!!! Помогите кто может... Надо в NetBeans в JTable1 закрасить одну ячейку красным...

Вывести матрицу: 1 красным цветом, 0 синим цветом
1 заменить на 2


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
11
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru