2010-01-07 43 views
2

我在使用FontDialog控件在VB.NET應用程序中。在FontDialog中顯示顏色選項,沒有下劃線和刪除選項

當我的ShowColor屬性設置爲true,它讓我三振出局影響組下劃線顏色選項。我只需要從這三個顏色

有什麼辦法來隱藏三振出局下劃線的影響,因此,只有顏色選項將是可見的?

+0

您好,感謝您的回覆。有沒有其他方法可以實現這一目標? – 2010-01-08 04:20:24

回答

0

我不認爲有可能隱藏或更改默認的Windows字體對話框。

對於你創建自己的自定義控制

感謝

Amitd

0

是其無法隱藏強調和FontDialog類 同時otherhand strickout選項,您可以通過不解決您的問題通過在樣式應用於目標文本之前處理它,在文本上顯示這些效果。

我希望你會得到點

問候, 與Atif

1
  • 派生ColorDialog
  • 覆蓋HookProc方法
  • 手柄WM_INITDIALOG消息(272)
  • 隱藏相應的對話框項目

這類似於ColorDialog類做什麼,當你設置ShowColor = falseShowEffects = true(什麼是默認):

protected override IntPtr HookProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam) 
{ 
    switch (msg) 
    { 
    case 272: 
     if (!this.showColor) 
     { 
     SafeNativeMethods.ShowWindow(new HandleRef((object) null, UnsafeNativeMethods.GetDlgItem(new HandleRef((object) null, hWnd), 1139)), 0); 
     SafeNativeMethods.ShowWindow(new HandleRef((object) null, UnsafeNativeMethods.GetDlgItem(new HandleRef((object) null, hWnd), 1091)), 0); 
     break; 
     } 
     else 
     break; 
    ... 
} 

上述隱藏「顏色」標籤和顏色組合(對話標識1139和1091) 。

你想要相反,隱藏Strikeout和下劃線。他們的對話ID是1040和1041(在Wine代碼中找到)。


全面推行「字體和顏色」對話框的@HansPassant的:

添加一個新類到您的項目並粘貼如下所示的代碼。編譯。將新組件從工具箱的頂部拖放到表單上,替換現有的FontDialog

Imports System.Runtime.InteropServices 

Public Class MyFontDialog 
    Inherits FontDialog 

    Protected Overrides Function HookProc(hWnd As IntPtr, msg As Integer, wparam As IntPtr, lparam As IntPtr) As IntPtr 
     If msg = 272 And Me.ShowColor Then '' WM_INITDIALOG 
      Dim strikeout = GetDlgItem(hWnd, &H410) 
      If strikeout <> IntPtr.Zero Then ShowWindow(strikeout, 0) 
      Dim underline = GetDlgItem(hWnd, &H411) 
      If underline <> IntPtr.Zero Then ShowWindow(underline, 0) 
     End If 
     Return MyBase.HookProc(hWnd, msg, wparam, lparam) 
    End Function 

    <DllImport("user32.dll")> _ 
    Private Shared Function GetDlgItem(hDlg As IntPtr, item As Integer) As IntPtr 
    End Function 
    <DllImport("user32.dll")> _ 
    Private Shared Function ShowWindow(hWnd As IntPtr, cmd As Integer) As Boolean 
    End Function 
End Class 

我確實需要這個了WinAPI的(C++ Builder中),因此,雖然略有題外話,我分享C++代碼WinAPI的太多。這是更看中的,因爲它甚至轉移顏色框起來:

RECT Rect; 
POINT Point; 

HWND StrikeoutHandle = GetDlgItem(Handle, 1040); 
GetWindowRect(StrikeoutHandle, &Rect); 
POINT StrikeoutPoint = { Rect.left, Rect.top }; 
ScreenToClient(Handle, &StrikeoutPoint); 

ShowWindow(StrikeoutHandle, SW_HIDE); 
ShowWindow(GetDlgItem(Handle, 1041), SW_HIDE); 

HWND LabelHandle = GetDlgItem(Handle, 1091); 
GetWindowRect(LabelHandle, &Rect); 
Point.x = Rect.left; 
Point.y = Rect.top; 
ScreenToClient(Handle, &Point); 

int Shift = StrikeoutPoint.y - Point.y; 

SetWindowPos(LabelHandle, NULL, Point.x, Point.y + Shift, 0, 0, 
    SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER); 

HWND ComboHandle = GetDlgItem(Handle, 1139); 
GetWindowRect(ComboHandle, &Rect); 
Point.x = Rect.left; 
Point.y = Rect.top; 
ScreenToClient(Handle, &Point); 
SetWindowPos(ComboHandle, NULL, Point.x, Point.y + Shift, 0, 0, 
    SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER); 

的結果是這樣的:

Font and color dialog

+0

我喜歡你的想法,並將其製作成可用的課程。隨意複製,因爲你認爲合適,我會刪除我的帖子。 – 2015-04-30 13:12:54

+0

謝謝!我合併了你的代碼。 – 2015-04-30 13:19:50

相關問題