BloggerAds廣告

2021年1月29日 星期五

[C#] WPD : How to make a hot key for application

在WPF的程式裡, 想要加入快捷鍵的功能
首先在Resources中建立Command的名稱, 這部份用來連結CommandBindings和InputBindings
<Window.Resources>
	<RoutedUICommand x:Key="OpenFile" Text="Open File"/>
</Window.Resources>
接下來設定CommandBindings
其中CommandBinding_Executed是執行的Function名稱
<Window.CommandBindings>
	<CommandBinding Command="{StaticResource OpenFile}" Executed="CommandBinding_Executed"/>
</Window.CommandBindings>
最後設定InputBindings
<Window.InputBindings>
	<KeyBinding Key="O" Modifiers="Ctrl" Command="{StaticResource OpenFile}"/>
</Window.InputBindings>

2021年1月22日 星期五

[C#] WPF : How to make a button looks like transparent

我試著在WPF的專案上, 讓Button看起來像是Label一樣 設定如下
<Button Name="btnTest" Click="BtnTest_Click" Background="{x:Null}" BorderBrush="{x:Null}">Test</Button>
如果設定成Style, Resource的設定如下
<Window.Resources>
	<Style TargetType="{x:Type Button}" x:Key="TransparentButton">
		<Setter Property="Background" Value="{x:Null}" />
		<Setter Property="BorderBrush" Value="{x:Null}" />
	</Style>
</Window.Resources>
而使用方式為

<Button
Style="{StaticResource TransparentButton}"
Name="btnTest"
Content="Test"
Click="BtnTest_Click"/>

2020年12月2日 星期三

[C#] How to convert JSON string to class on Visual Studio

 JSON格式的使用越來越多, 在撰寫部分轉成Class會方便許多

這是在Visual Studio中提供的功能


1. 複製JSON格式的文字

2. 在.cs檔案中, 點選Edit->Paste Special->Paste JSON As Classes


或是在QuickType.io也有提供轉換JSON的功能

2019年6月4日 星期二

[C Plue Plus] error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

在Build DirectShow的Sample時, 出現了此錯誤訊息.
網路上找了一下解法
將 operator=(LONG);改成 LONG operator=(LONG);
以下是發生原因
BaseClasses/ctlutil.h(278) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
错误发生在:operator=(LONG); 函数定义中,这是因为在VC6中,如果没有显示的指定返回值类型,编译器将其视为默认整型;但是vs2005不支持默认整型. 这个错误,解决方法如下:
打开project->BaseClasses properties->configuration->C/C++ ->Command Line,增加/wd4430选项。

2019年5月28日 星期二

使用region來整理程式碼

在Visual Studio開發C#的時候, 使用"#region 說明"和"#endregion"

在Android Studio開發時, 使用 "//region 說明"和"//endregion"

2018年3月16日 星期五

Epub Reader on C#

自己本身有在看epub的電子書

可是有些小說只有txt檔

在網路上可以找到轉換的網站, 但是有時候會不成功

所以想要自己寫隻程式來轉換

有找到別人寫好的dll, 使用nuget進行下載 Install-Package EpubSharp.dll

參考網址 : https://github.com/Asido/EpubSharp

2017年11月6日 星期一

Web.Config如何在不同的Build中使用不同的設定

目前遇到在不同的環境, 需要使用不同的設定進行開發

所以要一直改Web.Config的設定

因為太煩了, 所以找了利用不同的組態設定來切換在不同的環境下, 需要的設定值


http://kevintsengtw.blogspot.tw/2014/08/webconfig.html

https://blog.yowko.com/2017/04/webconfig-transform-when-debug.html

2017年10月9日 星期一

Visual Studio2013 Web Server無法進入Debug模式

今天在Debug專案時, 發現按下F5(Start Debug), 專案沒有進入Debug模式

找了一下設定, 找到了問題在哪

在Project->Properties->Web->Debugger中, 將ASP.NET點選

這樣就可以了

2017年10月5日 星期四

2017年10月1日 星期日

How to update NuGet version

在Build Project時出現了下面的錯誤

NuGet Package restore failed for project FinTechPty: The 'Newtonsoft.Json 10.0.3' package requires NuGet client version '2.12' or above, but the current NuGet version is '2.8.60610.756'..


這時候要去Tools -> Extensions and Updates, 然後更新NuGet

更新結束後重新開啟Project就可以了

2017年9月30日 星期六

SQL 資料庫的備份還原和匯入匯出

如果要將SQL中一個資料庫的匯出, 提供給其他工程師使用

可以利用以下的方式


  1. 備份/還原
    • 備份
    打開SQL Server Management Studio
    點選要匯出的資料庫
    按右鍵->選擇"工作"->"選擇"備份"
    指定要存放的路徑以及檔案名稱

    • 還原
    點選"資料庫"
    按右鍵->選擇"還原資料庫"
    來源選擇"裝置"->選取資料庫的備份檔
    按下確定即可完成

    有產生無法還原的問題, 可以試試在畫面右方"檔案"中
    點選"將所有檔案重新放置到資料夾"再按確定

  2. 匯出/匯入


    • 匯出
打開SQL Server Management Studio
點選要匯出的資料庫
按右鍵->選擇"工作"->"選擇"產生指令碼"
按下"下一步", 點選"編寫整個資料庫和所有資料庫物件的指令碼"
按下"下一步", 設定要儲存的檔案名稱後, 一直"下一步"即可完成
    •  匯入

 在SQL Server Management Studio的工具快捷列
 按下"新增查詢(New Query"
將匯出的SQL檔案內容貼上
按下快捷列上的"執行"即可完成

2017年9月28日 星期四

ASP.net MVC5 網站開發美學 - 0

最近開始學習MVC

網路上雖然有很多的教學

可是還是買了一本書, 再查詢資料的時候比較方便

順便整理一下書中的重點以後在查資料的時候能夠更加迅速

SQL匯入mdf 5120錯誤

最近在使用SQL Server, 嘗試建立資料庫

可是有時候欄位設定不完整, 又不知道怎麼重新設定

所以需要將之前的資料重新匯入

可是卻出了5120的錯誤

在網路上找的教學影片

需要注意的細節有以下兩點

1. 以系統管理員的身分執行SQL Server Manager
2. 需要將mdf路徑的權限開啟完全控制

就可以正常匯入了

匯入的方式 :
1. 在"資料庫"上, 點選右鍵, 選擇附加(Attach)
2. 選擇需要匯入的mdf檔案即可

2016年12月13日 星期二

2016年11月30日 星期三

2016年10月26日 星期三

[C#]PictureBox如何顯示網路圖片


範例程式
    ...
    pictureBox1.Imag = ReadImageFromUrl("http://xxxxx");
    ...

    private Image ReadImageFromUrl(string urlImagePath)
    {
        Uri uri = new Uri(urlImagePath);
        WebRequest webRequest = WebRequest.Create(uri);
        Stream stream = webRequest.GetResponse().GetResponseStream();
        Image res = Image.FromStream(stream);
        return res;
     }

或是使用
範例程式
    //這個方式顯示需要時間下載圖片後顯示
    pictureBox1.ImageLocation = "http://xxxxx";

參考網址 : 當麻許

[C#]How to pass multi parameters to thread


Thread如何傳遞多個參數?

之前都一直用全域變數來處理

後來認真找了資料, 感覺還不錯的處理方式

範例程式
    ...
    string p1 = "Yada yada.";
    long p2 = 4715821396025;
    int p3 = 4096;
    object args = new object[3] { p1, p2, p3 };
    Thread b1 = new Thread(new ParameterizedThreadStart(worker));
    b1.Start(args);
    ...
    private void worker(object args)
    {
      Array argArray = new object[3];
      argArray = (Array)args;
      string p1 = (string)argArray.GetValue(0);
      long p2 = (long)argArray.GetValue(1);
      int p3 = (int)argArray.GetValue(2);
      ...
    }

參考網址 :http://stackoverflow.com/questions/831009/thread-with-multiple-parameters

2016年10月21日 星期五

Facebook瀏覽/下載相簿

這幾天完成了C#的版本
想說做個網頁的版本
只是沒用過JavaScript
只能一邊做一邊查
剩下圖片大小縮放的功能
有時間再改了....