跳到主要內容

C# cheat sheet

how-do-i-generate-a-random-int-number

Random rnd = new Random();
int month = rnd.Next(1, 13);  // month: >= 1 and < 13

chart library




WindowsMediaPlayer pause

AxWindowsMediaPlayer1.Ctlcontrols.pause()

implement-keyboard-shortcuts-in-a-windows-forms-application

protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
  if (keyData == (Keys.Control | Keys.F)) {
    MessageBox.Show("What the Ctrl+F?");
    return true;
  }
  return base.ProcessCmdKey(ref msg, keyData);
}

play-video-files

// [ C# ]
WMPLib.WindowsMediaPlayer Player;

private void PlayFile(String url)
{
    Player = new WMPLib.WindowsMediaPlayer();
    Player.PlayStateChange +=
        new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(Player_PlayStateChange);
    Player.MediaError +=
        new WMPLib._WMPOCXEvents_MediaErrorEventHandler(Player_MediaError);
    Player.URL = url;
    Player.controls.play();
}

private void Form1_Load(object sender, System.EventArgs e)
{
    // TODO  Insert a valid path in the line below.
    PlayFile(@"c:\myaudio.wma");
}

private void Player_PlayStateChange(int NewState)
{
    if ((WMPLib.WMPPlayState)NewState == WMPLib.WMPPlayState.wmppsStopped)
    {
        this.Close();
    }
}

private void Player_MediaError(object pMediaObject)
{
    MessageBox.Show("Cannot play media file.");
    this.Close();
}
//http://msdn.microsoft.com/en-us/library/dd564582(VS.85).aspx
//https://www.codeproject.com/Articles/844451/Audio-and-Video-Player-Csharp-Winform

留言

這個網誌中的熱門文章

在Windows 10/8/7/Vista/XP中用shell指令存取特殊資料夾

特殊資料夾的位置定義在註冊表中 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\FolderDescriptions Windows 10的完整shell:指令列表 shell:AccountPictures shell:Roaming Tiles shell:Common Programs shell:PublicAccountPictures shell:GameTasks shell:UserProfiles shell:MyComputerFolder shell:SearchHistoryFolder shell:Local Pictures shell:SyncSetupFolder shell:DpapiKeys shell:Retail Demo shell:Favorites shell:My Video shell:SearchHomeFolder shell:RecordedTVLibrary shell:System shell:Libraries shell:ThisDeviceFolder shell:AppsFolder shell:MusicLibrary shell:CommonVideo shell:OneDriveDocuments shell:SyncResultsFolder shell:Cookies shell:CameraRollLibrary shell:Original Images shell:Recorded Calls shell:3D Objects shell:CommonMusic shell:OneDrivePictures shell:My Pictures shell:Cache shell:Local Videos shell:Downloads shell:SavedPictures shell:CommonDownloads shell:AppData shell:SyncCenterFolder shell:PublicLibraries shell:VideosLibrary shell:My Mus...

東西越少越幸福

東西越多 意味耗能越多,會不斷接收物品放出的信息 (1)。 代表花越多錢在上面。 要花的錢也多,東西佔滿屋子,要換更大的房子。 東西越少 意味整理時間少,有更多時間做自己想做的事。 空間多,時間多,心理更加清淨。 (1) 像婕翎的天使與魔鬼中演的,看到地上有一包錢,你會不會在那邊天人交戰,要不要撿起來。地上的垃圾當然也有這種效果,只是反應會比較快,一腳踢開,還是拿起來丟垃圾桶。房間堆滿東西,每天都看到這些東西,要做好多決定想想就覺得可怕。 買東西的原則 有價值的。 使用頻率高的。 東西盡量少買。 有更多時間學新技能,像 學谷歌拼音輸入法 ,讓自己打字更快。 買東西的沒原則 每次小小揮霍一下特開心。 擁有的東西就很多。 常感到後悔,自己為什麼買到不合適的衣服。 像花時間沒規劃一樣,翻開書就想上個網,玩個 天堂M 。