Hi there,
On the author’s website:
http://blogs.msdn.com/markrideout/archive/2006/01/08/510700.aspx
one of the comments contains the fix you need (someone else realized it requires styles, and wrote a check in case they’re not available). In case that blog ever disappears, here is the relevant code:
in «TreeGridView.cs» delete the followin’ two lines:
——8<——
internal VisualStyleRenderer rOpen = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Opened);
internal VisualStyleRenderer rClosed = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Closed);
——8<——
in «TreeGridCell.cs» find the line «if (node.HasChildren || node._grid.VirtualNodes)» and change it so that it looks like that:
——8<——
if (node.HasChildren || node._grid.VirtualNodes)
{
// Ensure that visual styles are supported.
if (Application.RenderWithVisualStyles)
{
VisualStyleRenderer rOpen = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Opened);
VisualStyleRenderer rClosed = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Closed);
// Paint node glyphs
if (node.IsExpanded)
//node._grid.rOpen.DrawBackground(graphics,
new Rectangle(glyphRect.X, glyphRect.Y + (glyphRect.Height / 2) — 4,
10, 10));
rOpen.DrawBackground(graphics, new
Rectangle(glyphRect.X, glyphRect.Y + (glyphRect.Height / 2) — 4, 10,
10));
else
//node._grid.rClosed.DrawBackground(graphics, new
Rectangle(glyphRect.X, glyphRect.Y + (glyphRect.Height / 2) — 4, 10,
10));
rClosed.DrawBackground(graphics, new
Rectangle(glyphRect.X, glyphRect.Y + (glyphRect.Height / 2) — 4, 10,
10));
}
else
{
int h = 8;
int w = 8;
int x = glyphRect.X;
int y = glyphRect.Y + (glyphRect.Height / 2) — 4;
//MessageBox.Show(«x = » + x.ToString() + «, y= » + y.ToString());
graphics.DrawRectangle(new Pen(SystemBrushes.ControlDark), x, y, w, h);
graphics.FillRectangle(new SolidBrush(Color.White), x + 1, y + 1, w — 1, h — 1);
graphics.DrawLine(new Pen(new SolidBrush(Color.Black)), x + 2, y + 4, x + w — 2, y + 4);
if (!node.IsExpanded)
graphics.DrawLine(new Pen(new SolidBrush(Color.Black)), x + 4, y + 2, x + 4, y + h — 2);
}
}
——8<——
Uswer 1644 / 1147 / 292 Регистрация: 26.06.2017 Сообщений: 3,110 |
||||
1 |
||||
03.02.2021, 22:14. Показов 2709. Ответов 6 Метки нет (Все метки)
Добрый день. Создаю собственную прорисовку ComboBox (см. код ниже), взято отсюда. Однако при добавлении элемента UserControl1 на форму возникает сообщение: Visual Styles-related operation resulted in an error because no visual style is currently active. (Операция с Visual Styles привела к ошибке, поскольку сейчас нет активных стилей отображения.). Никак не соображу, что делаю не так. Проблема исчезает при комментировании SetStyle, но тогда не вызывается OnPaint. В чём проблема? Кликните здесь для просмотра всего текста
0 |
ovva 4212 / 3361 / 817 Регистрация: 02.02.2013 Сообщений: 3,259 Записей в блоге: 2 |
||||
04.02.2021, 17:31 |
2 |
|||
Думаю, что если убрать InitializeComponent, все благополучно разрешиться.
Изображения
1 |
1644 / 1147 / 292 Регистрация: 26.06.2017 Сообщений: 3,110 |
|
04.02.2021, 18:21 [ТС] |
3 |
ovva, увы но не выходит.
0 |
4212 / 3361 / 817 Регистрация: 02.02.2013 Сообщений: 3,259 Записей в блоге: 2 |
|
04.02.2021, 19:55 |
4 |
Однако при добавлении элемента UserControl1 на форму возникает сообщение Такой проблемы не наблюдается. Это никакой не UserControl, а обычный класс, наследуемый от ComboBox. Для получения картинки выше использовался ваш код лишь слегка подредактированный.
увы но не выходит Вы бы пояснили, какого эффекта вы ожидаете.
0 |
1644 / 1147 / 292 Регистрация: 26.06.2017 Сообщений: 3,110 |
|
04.02.2021, 22:01 [ТС] |
5 |
Вы бы пояснили, какого эффекта вы ожидаете. Хочу такого эффекта как у Вас, а имею вот что (см. картинку). Миниатюры
0 |
ovva 4212 / 3361 / 817 Регистрация: 02.02.2013 Сообщений: 3,259 Записей в блоге: 2 |
||||||||
04.02.2021, 22:29 |
6 |
|||||||
такого эффекта как у Вас Вот код соответствующий приложенной картинке Кликните здесь для просмотра всего текста
Сам класс, вообщем то мало отличающийся от вашего кода.
PS. Среда:
0 |
Uswer 1644 / 1147 / 292 Регистрация: 26.06.2017 Сообщений: 3,110 |
||||
04.02.2021, 23:01 [ТС] |
7 |
|||
Решено. Ну и в догонку как правильно решить задачку:
P.S. Для меня остаётся загадкой почему ComboBoxRenderer не реализует отрисовку элементов для классического стиля.
1 |
IT_Exp Эксперт 87844 / 49110 / 22898 Регистрация: 17.06.2006 Сообщений: 92,604 |
04.02.2021, 23:01 |
Помогаю со студенческими работами здесь
Операция горизонтального отображения прямоугольной матрицы Очередь: операция удаления и отображения текущего состояния Стек: операция удаления и отображения текущего состояния Visual Studio 2013: С# Debug — не может начать отладку, поскольку цель отладки отсутствует Visual studio 2015 Не удалось запустить приложение, поскольку его параллельная конфигурация неправильная Установила приложение visual studio 2015 и выдает такую ошибку : Не удалось… Искать еще темы с ответами Или воспользуйтесь поиском по форуму: 7 |
While I look at my code, I wanted to provide the complete exception and the look at the TabControl after I click «Continue» on the exception dialog:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.InvalidOperationException: Visual Styles-related operation resulted in an error because no visual style is currently active.
at System.Windows.Forms.VisualStyles.VisualStyleRenderer.IsCombinationDefined(String className, Int32 part)
at System.Windows.Forms.VisualStyles.VisualStyleRenderer..ctor(String className, Int32 part, Int32 state)
at System.Windows.Forms.VisualStyles.VisualStyleRenderer..ctor(VisualStyleElement element)
at TabContol2.CustomTabControl.DrawControl(Graphics g)
at TabContol2.CustomTabControl.OnPaint(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.TabControl.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
—————————————-
DeliveryDispatch
Assembly Version: 1.0.3810.17731
Win32 Version: 1.0.3810.17731
CodeBase: file:///C:/Exit41/DeliveryDispatch/Program/DeliveryDispatch.exe
—————————————-
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
—————————————-
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
—————————————-
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
—————————————-
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
—————————————-
PizzaPilotRuntime
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Exit41/DeliveryDispatch/Program/PizzaPilotRuntime.DLL
—————————————-
System.Data
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
—————————————-
System.Transactions
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
—————————————-
System.EnterpriseServices
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
—————————————-
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
—————————————-
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
—————————————-
System.Web.Services
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Web.Services/2.0.0.0__b03f5f7f11d50a3a/System.Web.Services.dll
—————————————-
DeliveryDispatch.XmlSerializers
Assembly Version: 1.0.3810.17731
Win32 Version: 1.0.3810.17731
CodeBase: file:///C:/Exit41/DeliveryDispatch/Program/DeliveryDispatch.XmlSerializers.DLL
—————————————-
DDClientRuntime
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Exit41/DeliveryDispatch/Program/DDClientRuntime.DLL
—————————————-
DDClientCommon
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Exit41/DeliveryDispatch/Program/DDClientCommon.DLL
—————————————-
log4net
Assembly Version: 1.2.10.0
Win32 Version: 1.2.10.0
CodeBase: file:///C:/Exit41/DeliveryDispatch/Program/log4net.DLL
—————————————-
-vxbr1yj
Assembly Version: 1.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
—————————————-
DDClientLib
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Exit41/DeliveryDispatch/Program/DDClientLib.DLL
—————————————-
System.Messaging
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Messaging/2.0.0.0__b03f5f7f11d50a3a/System.Messaging.dll
—————————————-
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging=»true» />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
VisualStylesException.png
I got this error on my (normally stable) application after it had been running overnight. Attached is a stack trace. Could it be a bug in the toolbar?
—
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.InvalidOperationException: Visual Styles-related operation resulted in an error because no visual style is currently active.
at System.Windows.Forms.VisualStyles.VisualStyleRenderer.IsCombinationDefined(String className, Int32 part)
at System.Windows.Forms.VisualStyles.VisualStyleRenderer..ctor(String className, Int32 part, Int32 state)
at System.Windows.Forms.VisualStyles.VisualStyleRenderer..ctor(VisualStyleElement element)
at Infragistics.Win.FormattedLinkLabel.PositionElementsCache.MeasureTextGDIOrThemed(String text, Font font, TextFormatFlags textFormatFlags)
at Infragistics.Win.FormattedLinkLabel.PositionElementsCache.MeasureCharacterRangesGDI(String text, Font font, TextFormatFlags textFormatFlags, CharacterRange[] ranges)
at Infragistics.Win.FormattedLinkLabel.PositionElementsCache.ReMeasureParts(String text, Int32[] parts, Single[] widths, Int32 partStartIndex, Int32 partEndIndex, Font font, Single& lineHeight)
at Infragistics.Win.FormattedLinkLabel.PositionElementsCache.MeasureParts(String text, Int32[] parts, Font font, Single& lineHeight)
at Infragistics.Win.FormattedLinkLabel.NodeText.TextLayoutInfo.Measure(PositionElementsInfo& info)
at Infragistics.Win.FormattedLinkLabel.NodeText.PositionSelf(PositionElementsInfo& info)
at Infragistics.Win.FormattedLinkLabel.NodeBase.PositionHelper(PositionElementsInfo& info)
at Infragistics.Win.FormattedLinkLabel.NodeBase.Position(PositionElementsInfo& info)
at Infragistics.Win.FormattedLinkLabel.NodeBase.PositionChildNodes(PositionElementsInfo& info)
at Infragistics.Win.FormattedLinkLabel.NodeBlock.PositionChildNodes(PositionElementsInfo& info)
at Infragistics.Win.FormattedLinkLabel.NodeBase.PositionHelper(PositionElementsInfo& info)
at Infragistics.Win.FormattedLinkLabel.NodeBase.Position(PositionElementsInfo& info)
at Infragistics.Win.FormattedLinkLabel.NodeBase.CalcSize(IFormattedLinkLabelOwner owner, Graphics graphics, Int32 maxWidth)
at Infragistics.Win.FormattedLinkLabel.ParsedFormattedTextValue.CalcSize(Graphics graphics, Font baseFont, AppearanceData& defaultAppearance, Int32 widthConstraint, DefaultableBoolean wrapText, GdiDrawStringFlags gdiDrawStringFlags)
at Infragistics.Win.UltraWinToolbars.Ribbon.RibbonMetrics.CalculateCaptionAreaHeight()
at Infragistics.Win.UltraWinToolbars.Ribbon.RibbonMetrics.get_CaptionAreaHeight()
at Infragistics.Win.UltraWinToolbars.Ribbon.RibbonMetrics.get_RibbonHeight()
at Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea.RefreshDockAreaSize(Size& currentSize)
at Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea.RefreshDockAreaSize()
at Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea.DirtyChildElements()
at Infragistics.Win.UltraWinToolbars.UltraToolbarsManager.DirtyChildElements(Boolean delegateToMdiParent)
at Infragistics.Win.UltraWinToolbars.UltraToolbarsManager.DirtyChildElements()
at Infragistics.Win.UltraWinToolbars.UltraToolbarsManager.DirtyAllElements()
at Infragistics.Win.UltraWinToolbars.UltraToolbarsManagerRole.OnStyleChanged()
at Infragistics.Win.AppStyling.ComponentRole.ClearCache(Boolean notifyOwner)
at Infragistics.Win.AppStyling.ComponentRole.OnAppStyleChanged(Object sender, StyleChangedEventArgs e)
— End of inner exception stack trace —
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at Infragistics.Win.WeakReferenceMulticastDelegate`1.WeakReferenceProxyEventHandler.OnEventFired(Object sender, EventArgsType e, Type delegateType)
at Infragistics.Win.WeakReferenceMulticastDelegate`1.Invoke(Object sender, EventArgsType e)
at Infragistics.Win.AppStyling.StyleManager.NotifyThemeChanged()
at Infragistics.Win.XPThemes.OnThemeChangeMessage(Object sender, EventArgs e)
at Infragistics.Win.XPThemes.ThemeManagerForm.OnThemeChanged(EventArgs e)
at Infragistics.Win.XPThemes.ThemeManagerForm.OnNotifyMessage(Message m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.PeekMessage(MSG& msg, HandleRef hwnd, Int32 msgMin, Int32 msgMax, Int32 remove)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)