日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > asp.net >内容正文

asp.net

Paint.Net学习笔记——二、窗体(上)

發(fā)布時(shí)間:2025/4/5 asp.net 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Paint.Net学习笔记——二、窗体(上) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
在PDN順利執(zhí)行了啟動(dòng)邏輯后,就進(jìn)入Application.Run(new MainForm(arg))了,接下來(lái)我們一起來(lái)看看Main里面有什么奧秘。 進(jìn)入MainForm類(lèi),發(fā)現(xiàn)該類(lèi)繼承自PdnBaseForm類(lèi),而這個(gè)基類(lèi)的注釋里,說(shuō)明了該基類(lèi)用于修復(fù)Form類(lèi)中透明度不能為1.0的bug,那么我們之后再看,還是先看看MainForm(string[])構(gòu)造函數(shù)。 在該構(gòu)造函數(shù)中,一進(jìn)來(lái)先是檢查啟動(dòng)參數(shù)。(如何使用啟動(dòng)參數(shù)啟動(dòng)PDN?這里提供一個(gè)比較簡(jiǎn)單的方法:進(jìn)入CMD(命令行模式),進(jìn)入PDN安裝目錄中,并執(zhí)行paintdotnet.ext /splash或/test等啟動(dòng)參數(shù))。(splashForm是啟動(dòng)歡迎窗口) 如果沒(méi)有啟動(dòng)參數(shù),則構(gòu)造一個(gè)空白的畫(huà)布: 構(gòu)造空白畫(huà)布
????????????//?no?file?specified??create?a?blank?image
????????????if?(fileNames.Count?==?0)
????????????
{
????????????????
//設(shè)置畫(huà)布定位單位
??????????????????MeasurementUnit?units?=?Document.DefaultDpuUnit;
????????????????
double?dpu?=?Document.GetDefaultDpu(units);
????????????????Size?newSize?
=?this.appWorkspace.GetNewDocumentSize();
????????????????
this.appWorkspace.CreateBlankDocumentInNewWorkspace(newSize,?units,?dpu,?true);
????????????????
this.appWorkspace.ActiveDocumentWorkspace.IncrementJustPaintWhite();
????????????????
this.appWorkspace.ActiveDocumentWorkspace.Document.Dirty?=?false;
????????????}

以上代碼中,Document、AppWorkspace都是非常重要的概念,我以后會(huì)單獨(dú)說(shuō)明,現(xiàn)在還是繼續(xù)往下看。之后調(diào)用了LoadWindowState()來(lái)設(shè)置窗體尺寸。這個(gè)方法里仔細(xì)看一下,原來(lái)窗體初始化尺寸也是使用注冊(cè)表保存的,有興趣的朋友可以修改一下這些值看看效果。 初始化工作基本完成了,還有最后兩句:啟動(dòng)一個(gè)定時(shí)器以及注冊(cè)應(yīng)用程序空閑事件。這兩個(gè)事件我在這里也說(shuō)一下: 從定時(shí)器變量命名上看出,該定時(shí)器是用來(lái)延時(shí)一些操作的,轉(zhuǎn)到定時(shí)器出發(fā)事件中,我們看到定時(shí)器只執(zhí)行一次,執(zhí)行的方法為this.appWorkspace.ToolBar.MainMenu.PopulateEffects();。一路追蹤進(jìn)去,發(fā)現(xiàn)該方法的作用為“加載濾鏡PluginDLL”,使用延時(shí)定時(shí)器來(lái)觸發(fā)該方法,避免了應(yīng)用程序啟動(dòng)時(shí)需要加載過(guò)多DLL而造成假死現(xiàn)象。這樣做,大大加快了應(yīng)用程序的啟動(dòng)速度。 窗體初始化的最后,注冊(cè)了一句:Application_Idle事件。該事件在應(yīng)用程序空閑時(shí)觸發(fā)。追蹤到ProcessMessage方法,該方法用作處理在隊(duì)列中的Windows消息。 到這里,MainForm的初始化工作就全部完成了。下面我們?cè)倏纯丛摯绑w的一些重寫(xiě)方法和一些窗體注冊(cè)事件: OnDragDrop重寫(xiě)
????????protected?override?void?OnDragDrop(DragEventArgs?drgevent)
????????
{
????????????Activate();
????????????
if?(!IsCurrentModalForm?||?!Enabled)
????????????
{
????????????????
//?do?nothing
????????????}

????????????
else?if?(drgevent.Data.GetDataPresent(DataFormats.FileDrop))
????????????
{
????????????????
string[]?allFiles?=?(string[])drgevent.Data.GetData(DataFormats.FileDrop);
????????????????
if?(allFiles?==?null)
????????????????
{
????????????????????
return;
????????????????}

????????????????
string[]?files?=?PruneDirectories(allFiles);
????????????????
bool?importAsLayers?=?true;
????????????????
if?(files.Length?==?0)
????????????????
{
????????????????????
return;
????????????????}

????????????????
else
????????????????
{
????????????????????TaskButton?openTB?
=?new?TaskButton(
????????????????????????ImageResource.Get(
"Icons.MenuFileOpenIcon.png").Reference,
????????????????????????PdnResources.GetString(
"DragDrop.OpenOrImport.OpenButton.ActionText"),
????????????????????????PdnResources.GetString(
"DragDrop.OpenOrImport.OpenButton.ExplanationText"));
????????????????????
string?importLayersExplanation;
????????????????????
if?(this.appWorkspace.DocumentWorkspaces.Length?==?0)
????????????????????
{
????????????????????????importLayersExplanation?
=?PdnResources.GetString("DragDrop.OpenOrImport.ImportLayers.ExplanationText.NoImagesYet");
????????????????????}

????????????????????
else
????????????????????
{
????????????????????????importLayersExplanation?
=?PdnResources.GetString("DragDrop.OpenOrImport.ImportLayers.ExplanationText");
????????????????????}

????????????????????TaskButton?importLayersTB?
=?new?TaskButton(
????????????????????????ImageResource.Get(
"Icons.MenuLayersImportFromFileIcon.png").Reference,
????????????????????????PdnResources.GetString(
"DragDrop.OpenOrImport.ImportLayers.ActionText"),
????????????????????????importLayersExplanation);
????????????????????TaskButton?clickedTB?
=?TaskDialog.Show(
????????????????????????
this,
????????????????????????
new?Icon(PdnResources.GetResourceStream("Icons.Question.ico")),
????????????????????????PdnInfo.GetBareProductName(),
????????????????????????
null,
????????????????????????
false,
????????????????????????PdnResources.GetString(
"DragDrop.OpenOrImport.InfoText"),
????????????????????????
new?TaskButton[]?{?openTB,?importLayersTB,?TaskButton.Cancel?},
????????????????????????
null,
????????????????????????TaskButton.Cancel);
????????????????????
if?(clickedTB?==?openTB)
????????????????????
{
????????????????????????importAsLayers?
=?false;
????????????????????}

????????????????????
else?if?(clickedTB?==?importLayersTB)
????????????????????
{
????????????????????????importAsLayers?
=?true;
????????????????????}

????????????????????
else
????????????????????
{
????????????????????????
return;
????????????????????}

????????????????}

????????????????
if?(!importAsLayers)
????????????????
{
????????????????????
//?open?files?into?new?tabs
????????????????????this.appWorkspace.OpenFilesInNewWorkspace(files);
????????????????}

????????????????
else
????????????????
{
????????????????????
//?no?image?open??we?will?have?to?create?one
????????????????????if?(this.appWorkspace.ActiveDocumentWorkspace?==?null)
????????????????????
{
????????????????????????Size?newSize?
=?this.appWorkspace.GetNewDocumentSize();
????????????????????????
this.appWorkspace.CreateBlankDocumentInNewWorkspace(
????????????????????????????newSize,
????????????????????????????Document.DefaultDpuUnit,
????????????????????????????Document.GetDefaultDpu(Document.DefaultDpuUnit),
????????????????????????????
false);
????????????????????}

????????????????????ImportFromFileAction?action?
=?new?ImportFromFileAction();
????????????????????HistoryMemento?ha?
=?action.ImportMultipleFiles(this.appWorkspace.ActiveDocumentWorkspace,?files);
????????????????????
if?(ha?!=?null)
????????????????????
{
????????????????????????
this.appWorkspace.ActiveDocumentWorkspace.History.PushNewMemento(ha);
????????????????????}

????????????????}

????????????}

????????????
base.OnDragDrop(drgevent);
????????}

以上代碼重寫(xiě)了DragDrop方法,分析一下它做了什么。 string[] files = PruneDirectories(allFiles);獲取了所有拖拽入窗體的文件列表,然后使用TashDialog詢問(wèn)直接打開(kāi)新文件還是在新圖層中添加。 TaskDialog類(lèi)提供了PDN中所有詢問(wèn)窗口的ShowDialog方法,并返回TaskButton對(duì)象,TaskButton對(duì)象中封裝了詢問(wèn)按鈕提示文字,顯示圖片以及DialogResult等,這各類(lèi)所提供的詢問(wèn)窗口定制性強(qiáng),而且顯示美觀,值得參考! 在接到用戶選擇的TaskButton結(jié)果后,執(zhí)行相應(yīng)的方法1.往當(dāng)前Workspace中添加新DocumentView。2.在當(dāng)前DocumentView中添加新圖層。(DoucmentView也是重要概念,以后再講)。接著,構(gòu)造了一個(gè)HistoryMemento對(duì)象。該對(duì)象描述了PDN應(yīng)喲個(gè)程序中的“歷史記錄”,該類(lèi)以后成立專(zhuān)題研究。 this.appWorkspace.ActiveDocumentWorkspace.History.PushNewMemento(ha);將剛才構(gòu)造的歷史記錄推入活動(dòng)的DocumentView中。 原來(lái)我們使用拖拽文件到PDN中,并彈出對(duì)話框等一系列過(guò)程是如此的~。 我們繼續(xù)研究。MainForm重寫(xiě)了OnClosing事件,里面調(diào)用了SaveSetting()方法: 保存設(shè)置
????????private?void?SaveSettings()
????????
{
????????????Settings.CurrentUser.SetInt32(PdnSettings.Width,?
this.Width);
????????????Settings.CurrentUser.SetInt32(PdnSettings.Height,?
this.Height);
????????????Settings.CurrentUser.SetInt32(PdnSettings.Top,?
this.Top);
????????????Settings.CurrentUser.SetInt32(PdnSettings.Left,?
this.Left);
????????????Settings.CurrentUser.SetString(PdnSettings.WindowState,?
this.WindowState.ToString());
????????????Settings.CurrentUser.SetBoolean(PdnSettings.TranslucentWindows,?PdnBaseForm.EnableOpacity);
????????????
if?(this.WindowState?!=?FormWindowState.Minimized)
????????????
{
????????????????Settings.CurrentUser.SetBoolean(PdnSettings.ToolsFormVisible,?
this.appWorkspace.Widgets.ToolsForm.Visible);
????????????????Settings.CurrentUser.SetBoolean(PdnSettings.ColorsFormVisible,?
this.appWorkspace.Widgets.ColorsForm.Visible);
????????????????Settings.CurrentUser.SetBoolean(PdnSettings.HistoryFormVisible,?
this.appWorkspace.Widgets.HistoryForm.Visible);
????????????????Settings.CurrentUser.SetBoolean(PdnSettings.LayersFormVisible,?
this.appWorkspace.Widgets.LayerForm.Visible);
????????????}

????????????SnapManager.Save(Settings.CurrentUser);
????????????
this.appWorkspace.SaveSettings();
????????}

把值設(shè)置到注冊(cè)表
????????/**////?<summary>
????????
///?把值保存到注冊(cè)表中
????????
///?</summary>
????????
///?<param?name="key">The?name?of?the?key?to?set.</param>
????????
///?<param?name="value">The?new?value?of?the?key.</param>

????????public?void?SetObject(string?key,?object?value)
????????
{
????????????
using?(RegistryKey?pdnKey?=?CreateSettingsKey(true))
????????????
{
????????????????pdnKey.SetValue(key,?value);
????????????}

????????}

該方法里把窗體的尺寸,位置等保存到了注冊(cè)表中,那么下次用戶再啟動(dòng)應(yīng)用程序的時(shí)候就可以把窗體恢復(fù)到最近一次關(guān)閉的狀態(tài)了。在appWorkspace.SveSettings()追蹤進(jìn)去,發(fā)現(xiàn)了一個(gè)SaveMruList()的方法。該方法是將“最近打開(kāi)列表”保存到注冊(cè)表中。

轉(zhuǎn)載于:https://www.cnblogs.com/wuxingsheng1984/archive/2008/11/14/1333720.html

總結(jié)

以上是生活随笔為你收集整理的Paint.Net学习笔记——二、窗体(上)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。