Попытка изменить цвет рамки маркировки

Мне наконец удалось это исправить с помощью подсказки из этого ответа . Я добавил следующую строку в web.config:


  
    
      
        
        
        
      
    
  

25
задан Stewbob 11 September 2009 в 14:50
поделиться

3 ответа

Если вы не хотите создавать пользовательский элемент управления, вы можете попробовать следующее:

Подключитесь к событию рисования метки.

void label1_Paint(object sender, PaintEventArgs e)
{
    ControlPaint.DrawBorder(e.Graphics, label1.DisplayRectangle, Color.Blue, ButtonBorderStyle.Solid);
}

Взято из здесь от Андрея Тозона

33
ответ дан 28 November 2019 в 20:43
поделиться

Я объединил решения robin.ellis и orandov, чтобы получить результат, который лучше всего работал у меня. Я создал настраиваемый элемент управления, который унаследовал объект Label, а затем переопределил событие OnPaint.

Public Class nomLabel
   Inherits Label

  Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
      MyBase.OnPaint(e)

      ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, myColor, ButtonBorderStyle.Solid)
   End Sub

End Class

Спасибо за помощь!

12
ответ дан 28 November 2019 в 20:43
поделиться

I ran into this problem as well and ended up using a workaround.

Create a custom control which consists of a label wrapped in a panel.

You can then use the panel to create your border and change it's color to whatever you want.

I've found that it's a good idea (although a little time consuming) to wrap all controls in your application anyways, because when it comes to finding out you need a custom property, or change to all of your controls of that type, you can just change the base control and your entire app changes.

8
ответ дан 28 November 2019 в 20:43
поделиться
Другие вопросы по тегам:

Похожие вопросы: