From 1db99cf1871f43e4700181c3ff799b5fbf5f444f Mon Sep 17 00:00:00 2001 From: abdelkader Date: Fri, 14 Apr 2023 17:52:02 -0400 Subject: [PATCH 1/2] extension capital letter --- vCardEditor/View/Customs/AddressTabControl.cs | 94 +++++++++++++++++++ vCardEditor/View/MainForm.cs | 8 +- 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 vCardEditor/View/Customs/AddressTabControl.cs diff --git a/vCardEditor/View/Customs/AddressTabControl.cs b/vCardEditor/View/Customs/AddressTabControl.cs new file mode 100644 index 0000000..3ab3cba --- /dev/null +++ b/vCardEditor/View/Customs/AddressTabControl.cs @@ -0,0 +1,94 @@ +using System; +using System.Drawing; +using System.Runtime.InteropServices; +using System.Windows.Forms; + +namespace vCardEditor.View.Customs +{ + class AddressTabControl : TabControl + { + public event EventHandler AddTab; + public AddressTabControl() + { + Padding = new Point(12, 4); + + DrawMode = TabDrawMode.OwnerDrawFixed; + DrawItem += tbcAddress_DrawItem; + MouseDown += tbcAddress_MouseDown; + Selecting += tbcAddress_Selecting; + HandleCreated += tbcAddress_HandleCreated; + } + + [DllImport("user32.dll")] + private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp); + private const int TCM_SETMINTABWIDTH = 0x1300 + 49; + + private void tbcAddress_HandleCreated(object sender, EventArgs e) + { + SendMessage(Handle, TCM_SETMINTABWIDTH, IntPtr.Zero, (IntPtr)16); + } + + private void tbcAddress_Selecting(object sender, TabControlCancelEventArgs e) + { + if (e.TabPageIndex == TabCount - 1) + e.Cancel = true; + } + + + private void tbcAddress_MouseDown(object sender, MouseEventArgs e) + { + var lastIndex = TabCount - 1; + if (GetTabRect(lastIndex).Contains(e.Location)) + { + AddTab?.Invoke(sender, e); + //TabPages.Insert(lastIndex, "New Tab"); + SelectedIndex = lastIndex; + + } + else + { + for (var i = 0; i < TabPages.Count; i++) + { + var tabRect = GetTabRect(i); + tabRect.Inflate(-2, -2); + var closeImage = Properties.Resources.Close; + var imageRect = new Rectangle( + (tabRect.Right - closeImage.Width), + tabRect.Top + (tabRect.Height - closeImage.Height) / 2, + closeImage.Width, + closeImage.Height); + if (imageRect.Contains(e.Location)) + { + TabPages.RemoveAt(i); + break; + } + } + } + } + + private void tbcAddress_DrawItem(object sender, DrawItemEventArgs e) + { + var tabPage = TabPages[e.Index]; + var tabRect = GetTabRect(e.Index); + tabRect.Inflate(-2, -2); + + if (e.Index == TabCount - 1) + { + var addImage = Properties.Resources.Add; + e.Graphics.DrawImage(addImage, + tabRect.Left + (tabRect.Width - addImage.Width) / 2, + tabRect.Top + (tabRect.Height - addImage.Height) / 2); + } + else + { + var closeImage = Properties.Resources.Close; + e.Graphics.DrawImage(closeImage, + (tabRect.Right - closeImage.Width), + tabRect.Top + (tabRect.Height - closeImage.Height) / 2); + TextRenderer.DrawText(e.Graphics, tabPage.Text, tabPage.Font, + tabRect, tabPage.ForeColor, TextFormatFlags.Left); + } + } + + } +} diff --git a/vCardEditor/View/MainForm.cs b/vCardEditor/View/MainForm.cs index b4c7c39..5b577bb 100644 --- a/vCardEditor/View/MainForm.cs +++ b/vCardEditor/View/MainForm.cs @@ -44,13 +44,19 @@ namespace vCardEditor.View { InitializeComponent(); resources = new ComponentResourceManager(typeof(MainForm)); - + tbcAddress.AddTab += TbcAddress_AddTab; BuildMRUMenu(); } + private void TbcAddress_AddTab(object sender, EventArgs e) + { + // MessageBox.Show("Test"); + } + + private void tbsOpen_Click(object sender, EventArgs e) { NewFileOpened?.Invoke(sender, new EventArg(string.Empty)); From 2325b5f98697ae567959ca88e0e9eb249a1bff1c Mon Sep 17 00:00:00 2001 From: abdelkader Date: Fri, 14 Apr 2023 17:52:18 -0400 Subject: [PATCH 2/2] file extension capital letter --- vCardEditor/Presenter/MainPresenter.cs | 2 +- vCardEditor/View/MainForm.cs | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/vCardEditor/Presenter/MainPresenter.cs b/vCardEditor/Presenter/MainPresenter.cs index 06cccb5..638389c 100644 --- a/vCardEditor/Presenter/MainPresenter.cs +++ b/vCardEditor/Presenter/MainPresenter.cs @@ -135,7 +135,7 @@ namespace VCFEditor.Presenter if (!string.IsNullOrEmpty(path)) { string ext = _repository.GetExtension(path); - if (ext != ".vcf") + if (!string.Equals(ext, ".vcf", StringComparison.OrdinalIgnoreCase)) { _view.DisplayMessage("Only vcf extension accepted!", "Error"); return; diff --git a/vCardEditor/View/MainForm.cs b/vCardEditor/View/MainForm.cs index 5b577bb..e2c1eb0 100644 --- a/vCardEditor/View/MainForm.cs +++ b/vCardEditor/View/MainForm.cs @@ -44,17 +44,12 @@ namespace vCardEditor.View { InitializeComponent(); resources = new ComponentResourceManager(typeof(MainForm)); - tbcAddress.AddTab += TbcAddress_AddTab; + BuildMRUMenu(); } - private void TbcAddress_AddTab(object sender, EventArgs e) - { - // MessageBox.Show("Test"); - } - - + private void tbsOpen_Click(object sender, EventArgs e)