TabControlのタブをDisableにする(WinForms)

c# - TabControl.DrawItem not firing on user painted TabControl - Stack Overflow
http://stackoverflow.com/questions/3115321/tabcontrol-drawitem-not-firing-on-user-painted-tabcontrol


DrawItemイベントが起きないタイミングで描画しなおすにはInvalidate()すれば良いと思いますが、他に方法あれば教えてください。

TabControl1.DrawMode = TabDrawMode.OwnerDrawFixed
AddHandler TabControl1.DrawItem, New DrawItemEventHandler(AddressOf TabControl1_DrawItem)
AddHandler TabControl1.Selecting, New TabControlCancelEventHandler(AddressOf TabControl1_Selecting)

Private Sub TabControl1_DrawItem(sender As Object, e As DrawItemEventArgs)
    Dim tabPage = TabControl1.TabPages(e.Index)
    Dim bounds = CType(e.Bounds, RectangleF)
    Using fmt = New StringFormat()
        fmt.Alignment = StringAlignment.Center
        fmt.LineAlignment = StringAlignment.Center
        If tabPage.Enabled Then
            Using brush = New SolidBrush(tabPage.ForeColor)
                e.Graphics.DrawString(tabPage.Text, tabPage.Font, brush, bounds, fmt)
            End Using
        Else
            Using brush = New SolidBrush(SystemColors.GrayText)
                e.Graphics.DrawString(tabPage.Text, tabPage.Font, brush, bounds, fmt)
            End Using
        End If
    End Using
End Sub

Private Sub TabControl1_Selecting(sender As Object, e As TabControlCancelEventArgs)
    If Not e.TabPage.Enabled Then
        e.Cancel = True
    End If
End Sub

TabControlの子コントロールを強制的に作成する(WinForms)

TabControl クラス (System.Windows.Forms)
https://msdn.microsoft.com/ja-jp/library/system.windows.forms.tabcontrol(v=vs.100).aspx

TabPageに含まれるコントロールは、タブ ページが表示されるまで作成されません。また、これらのコントロール内のいずれのデータ バインディングも、タブ ページが表示されるまでアクティブになりません。

TabPageに含まれるコントロールだけでなくTabPageのデータバインディングもアクティブにならない様子。というわけでリフレクションを使用してCreateControlします。パブリックメソッドのCreateControl()は効きませんでした。

Dim mi = GetType(TabControl).GetMethod("CreateControl", BindingFlags.Instance Or BindingFlags.NonPublic)
mi.Invoke(TabControl1, New Object() {True})

よくわかりませんが、BindingContextだけ設定すれば済むケースもあるかもしれません。

TabControl1.BindingContext = Me.BindingContext;

C# Winforms TabControl elements reading as empty until TabPage selected - Stack Overflow
http://stackoverflow.com/questions/2678184/c-sharp-winforms-tabcontrol-elements-reading-as-empty-until-tabpage-selected

ToolStripButtonの外観を変更する。(WinForms)

ToolStripProfessionalRendererを継承して好きなように描画する。
下記の例は
・ToolStripButtonに枠線を描画する
・ToolStripの角丸をやめる
の二点を行う例。

ToolStrip1.Renderer = New ToolStripRectRenderer()


''' <summary>
''' ToolStrip オブジェクトの描画機能を、カスタムのパレットおよび簡素化されたスタイルを適用することによって処理します。
''' </summary>
''' <remarks>ツールバーの角丸やめる。ボタンに枠線を描く。</remarks>
Private Class ToolStripRectRenderer
    Inherits ToolStripProfessionalRenderer

#Region "コンストラクタ"

    ''' <summary>
    ''' クラスの新しいインスタンスを初期化します。
    ''' </summary>
    Public Sub New()
        ' 角丸をやめる。影がツールバー右端下側にゴミのように見えるため。
        RoundedEdges = False
    End Sub

#End Region

#Region "オーバーライドされたメソッド"

    ''' <summary>
    ''' RenderButtonBackground  イベントを発生させます。
    ''' </summary>
    ''' <param name="e">イベント データを格納している System.Windows.Forms.ToolStripRenderEventArgs。</param>
    Protected Overrides Sub OnRenderButtonBackground(e As ToolStripItemRenderEventArgs)

        MyBase.OnRenderButtonBackground(e)

        If e.Item.Selected Then
            Return
        End If

        ' ボタンに枠線を表示する。
        Dim bounds = New Rectangle(Point.Empty, e.Item.Size)
        bounds.Width -= 1
        bounds.Height -= 1
        e.Graphics.DrawRectangle(SystemPens.ButtonShadow, bounds)

    End Sub

#End Region

End Class

エクスプローラーのライブラリの"表示"を好みの設定に変える(windows10)

Change folder view template for all folders in Windows 10 - Winaero
http://winaero.com/blog/change-folder-view-template-for-all-folders-in-windows-10/

私の環境(Win10 Pro 1607)ではちょくちょく元に戻るので効いているのかどうか
分かりませんが、やらないよりは大分マシです。
また、ライブラリからその下のフォルダに行くと反映されないので甚だ不完全です。

次の各フォルダの設定を好みの"表示"に変える。
C:\Users
C:\Users\\Documents
%HOMEPATH%\Music
%HOMEPATH%\Pictures
%HOMEPATH%\Videos

それぞれ、[フォルダーオプション]ダイアログの[表示]タブの
[フォルダーに適用(L)]をクリックして設定を反映させる。

目的のライブラリの設定を[ライブラリ ツール]-[管理]-
[このライブラリを次の目的に最適化]等から好みの設定に変更する。

以上。

おまけ

How to: Change Default Icon View in Windows 10 (for All Folders) | www.infopackets.com
https://www.infopackets.com/news/9764/how-change-default-icon-view-windows-10-all-folders

エクスプローラーの"表示"を変更するショートカット。
デスクトップでも効く。

CTRL + SHIFT + 1 Extra Large
CTRL + SHIFT + 2 Large Icons
CTRL + SHIFT + 3 Medium Icons
CTRL + SHIFT + 4 Small Icons
CTRL + SHIFT + 5 List
CTRL + SHIFT + 6 Details
CTRL + SHIFT + 7 Tiles
CTRL + SHIFT + 8 Content

DataGridViewのAutoGenerateColumnsで利用できる属性(WinForms)

DisplayNameAttributeでDataGridViewColumn.HeaderTextが指定できる。
BrowsableAttributeにfalseを指定で、自動生成から除外できる。


c# - Is there an Attribute I can use in my class to tell DataGridView not to create a column for it when bound to a List - Stack Overflow
http://stackoverflow.com/questions/1066907/is-there-an-attribute-i-can-use-in-my-class-to-tell-datagridview-not-to-create-a

DataGridViewDataConnection.cs
http://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/DataGridViewDataConnection.cs,2cc4e2a42be6fd3c
GetCollectionOfBoundDataGridViewColumns()の1047行目辺り

http://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/DataGridViewMethods.cs,bfbecf07c1463ef9,references
AutoGenerateDataBoundColumns(DataGridViewColumn[] boundColumns)の1571行目辺り

複数のファイルを開くバッチ

@echo off
cd C:\hoge
start "" "fuga.xlsx"
start "" "piyo.xlsx"

普通はコマンド拡張機能が有効なので、ファイルの関連付けを使って開くことができる。

startコマンドを使うのは、そうしないと閉じるまで次のファイルを開けないため。
startコマンドの最初の引数はコマンドウィンドウのタイトル。

DataGridViewのスクロールバーを有効にする(WinForms)

DataGridView1.Controls[0].Enabled = true; // Index zero is the horizontal scrollbar
DataGridView1.Controls[1].Enabled = true; // Index one is the vertical scrollbar

DataGridView Vertical Scroll is disabled.
https://social.msdn.microsoft.com/Forums/windows/en-US/bbf96688-76b2-4676-9f92-110e909faee1/datagridview-vertical-scroll-is-disabled?forum=winformsdesigner