以 TextBox 為例,點選控件右上角的三角符號,跳出來的 TextBox 工作,就是所謂的智能標籤
要建立智能標籤,要先引用 System.Design.dll
using System;
namespace EnumFlags
{
class Program
{
static void Main(string[] args)
{
Days days = Days.Saturday;
Console.WriteLine($"初始值:{days}");
days = days.Add(Days.Sunday);
Console.WriteLine($"把星期日加入:{days}");
days = days.Remove(Days.Saturday);
Console.WriteLine($"把星期六移除:{days}");
Console.WriteLine($"星期六日是否同時存在:{days.IsSatAndSunBoth()}");
Console.WriteLine($"星期六日是否存在一日:{days.IsSatOrSunExists()}");
}
}
// 沒有特別宣告的話,Enum 預設是 int
[Flags]
public enum Days
{
Monday = 1,
Tuesday = 2 ,
Wednesday = 4,
Thursday = 8 ,
Friday = 16,
Saturday = 32,
Sunday = 64,
All = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday
};
public static class ExtDays
{
public static Days Add(this Days source, Days flagAdd)
{
return source | flagAdd;
}
public static Days Remove(this Days source, Days flagRemove)
{
return source & ~flagRemove;
}
// 星期六日是否同時存在
public static bool IsSatAndSunBoth(this Days value)
{
return value.HasFlag(Days.Saturday | Days.Sunday);
}
// 星期六日是否存在一日
public static bool IsSatOrSunExists(this Days value)
{
return value.HasFlag(Days.Saturday) || value.HasFlag(Days.Sunday);
}
}
}
一開始練習時,因為是根據官方文章把 Enum 值,從 0 開始往後編,偏偏又用 [值為 0 的列舉] 來初始化,FlagAttribute 怎麼都加不上去,閱讀 [FlagsAttribute 指方針] 才發現到問題點
用作 None 值為零之旗標列舉常數的名稱。 您無法使用 None 位 and 運算中的列舉常數來測試旗標,因為結果一律為零。 不過,您可以在數值和列舉常數之間執行邏輯(而非位比較), None 以判斷是否已設定數值中的任何位。
如果您建立一個值列舉,而不是旗標列舉,則建立列舉常數仍然是值得的 None 。 原因是,通用語言執行時間預設會將用於列舉的記憶體初始化為零。 因此,如果您未定義其值為零的常數,則在建立時,列舉會包含不合法的值。
如果您的應用程式有明顯的預設情況,您的應用程式需要表示,請考慮使用其值為零的列舉常數來表示預設值。 如果沒有預設案例,請考慮使用值為零的列舉常數,表示不是任何其他列舉常數所表示的大小寫。
using System;
using System.IO;
namespace ReadOnlyFileDelete
{
class Program
{
static void Main(string[] args)
{
string targetFileFullName = @"D:\Demo.txt";
if (!File.Exists(targetFileFullName))
throw new FileNotFoundException();
// 利用 FileInfo
FileInfo fi = new FileInfo(targetFileFullName);
if (fi.IsReadOnly) fi.IsReadOnly = false;
fi.Delete();
}
}
}
FileAttribute 取消唯讀
using System;
using System.IO;
namespace ReadOnlyFileDelete
{
class Program
{
static void Main(string[] args)
{
string targetFileFullName = @"D:\Demo.txt";
if (!File.Exists(targetFileFullName))
throw new FileNotFoundException();
FileAttributes attributes = File.GetAttributes(targetFileFullName);
if (attributes.HasFlag(FileAttributes.ReadOnly))
{
attributes = attributes & ~FileAttributes.ReadOnly;
File.SetAttributes(targetFileFullName, attributes);
}
File.Delete(targetFileFullName);
}
}
}
USE [AdventureWorks2017]
GO
CREATE TABLE [dbo].[tblChar]
(
[NOs] [char](11) NOT NULL, -- 資料形態為 char
CONSTRAINT [PK_tblChar] PRIMARY KEY CLUSTERED ([NOs] ASC)
)
GO
CREATE TABLE [dbo].[tblNChar]
(
[ID] [int] NOT NULL,
[Nos] [nchar](11) NULL, -- 資料形態為 nchar
CONSTRAINT [PK_tblNChar] PRIMARY KEY CLUSTERED
(
[ID] ASC
)
)
GO
針對兩個 Table 進行 JOIN,來呈現 Hash Join 內有 Probe Residual 情況SELECT T1.*
FROM tblChar AS T1
JOIN tblNChar AS T2 ON T1.NOs = T2.NOs
完整執行計畫 SELECT T1.*
FROM tblChar AS T1
INNER Hash JOIN tblNChar -- 連結提示,強迫 TSQL 跑 Hash Join
AS T2 ON T1.NOs = T2.NOs
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ConfigSample.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ConfigSample.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<userSettings>
<ConfigSample.Properties.Settings>
<setting name="BGColor" serializeAs="String">
<value />
</setting>
<setting name="LocationX" serializeAs="String">
<value>0</value>
</setting>
<setting name="LocationY" serializeAs="String">
<value>0</value>
</setting>
<setting name="BindingText" serializeAs="String">
<value>控件綁定</value>
</setting>
</ConfigSample.Properties.Settings>
</userSettings>
<applicationSettings>
<ConfigSample.Properties.Settings>
<setting name="Title" serializeAs="String">
<value>[C#] 應用程式設定檔 - Settings.settngs</value>
</setting>
</ConfigSample.Properties.Settings>
</applicationSettings>
</configuration>
using WeifenLuo.WinFormsUI.Docking;
namespace DockSample
{
public partial class frmDock : DockContent
{
public frmDock()
{
InitializeComponent();
}
}
}
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
namespace DockSample
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
// frmMain 必須開啟 IsMdiContainer
this.IsMdiContainer = true;
// 設定 DockPanel 置中
dockPanel.Dock = DockStyle.Fill;
// 不允許使用者移動 DockPanel 內視窗 (Form)
dockPanel.AllowEndUserDocking = false;
// 設定 DockPanel Theme
dockPanel.Theme = new VS2015BlueTheme();
// 根據 DockState 把 frmDock 釘在 frmMain.DockPanel 上
frmDock frmDocument = new frmDock() { TabText = "Document" };
frmDocument.Show(this.dockPanel, DockState.Document);
frmDock frmDockLeft = new frmDock() { TabText = "DockLeft" }; ;
frmDockLeft.Show(this.dockPanel, DockState.DockLeft);
frmDock frmDockRight = new frmDock() { TabText = "DockRight" }; ;
frmDockRight.Show(this.dockPanel, DockState.DockRight);
frmDock frmDockBottom = new frmDock() { TabText = "DockBottom" }; ;
frmDockBottom.Show(this.dockPanel, DockState.DockBottom);
frmDock frmDockLeftAutoHide = new frmDock() { TabText = "DockLeftAutoHide" }; ;
frmDockLeftAutoHide.Show(this.dockPanel, DockState.DockLeftAutoHide);
frmDock frmFloat = new frmDock() { TabText = "Float" }; ;
frmFloat.Show(this.dockPanel, DockState.Float);
}
}
}