דילוג לתוכן
  • דף הבית
  • קטגוריות
  • פוסטים אחרונים
  • משתמשים
  • חיפוש
  • חוקי הפורום
כיווץ
תחומים

תחומים - פורום חרדי מקצועי

💡 רוצה לזכור קריאת שמע בזמן? לחץ כאן!
pcinfogmachP

pcinfogmach

@pcinfogmach
אודות
פוסטים
691
נושאים
185
שיתופים
0
קבוצות
0
עוקבים
3
עוקב אחרי
1

פוסטים

פוסטים אחרונים הגבוה ביותר שנוי במחלוקת

  • שאלה בwpf האם יש דרך להסיר את הצל שסביב האובייקט window
    pcinfogmachP pcinfogmach

    @pcinfogmach כתב בשאלה בwpf האם יש דרך להסיר את הצל שסביב האובייקט window:

    אבל מסתבר שאם עושים את זה אז מאבדים את היכולת לשנות את הגודל של החלון.

    עריכה: צריך לעשות כך במקום

    <WindowChrome.WindowChrome>
        <WindowChrome GlassFrameThickness="0"
                      CornerRadius="0"
                      CaptionHeight="0"/>
    </WindowChrome.WindowChrome>
    

    מצו"ב על הדרך קוד לuserform עם אפשרות דומה לחלון של הגדלה וגרירה (לא מושלם אבל עובד)

    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    
    namespace newresizableusercontrol
    {
        public partial class MainWindow : Window
        {
            private enum HitType
            {
                None, Body, UL, UR, LR, LL, L, R, B, T
            };
    
            private HitType MouseHitType = HitType.None;
            private bool DragInProgress = false;
            private Point LastPoint;
    
            public MainWindow()
            {
                InitializeComponent();
            }
    
            private HitType SetHitType(Grid grid, Point point)
            {
                double left = Canvas.GetLeft(grid);
                double top = Canvas.GetTop(grid);
                double right = left + grid.Width;
                double bottom = top + grid.Height;
                const double GAP = 10;
    
                if (point.X < left || point.X > right || point.Y < top || point.Y > bottom)
                    return HitType.None;
    
                if (point.X - left < GAP)
                {
                    if (point.Y - top < GAP) return HitType.UL;
                    if (bottom - point.Y < GAP) return HitType.LL;
                    return HitType.L;
                }
                else if (right - point.X < GAP)
                {
                    if (point.Y - top < GAP) return HitType.UR;
                    if (bottom - point.Y < GAP) return HitType.LR;
                    return HitType.R;
                }
    
                if (point.Y - top < GAP) return HitType.T;
                if (bottom - point.Y < GAP) return HitType.B;
                return HitType.Body;
            }
    
            private void SetMouseCursor()
            {
                Cursor desiredCursor = Cursors.Arrow;
    
                switch (MouseHitType)
                {
                    case HitType.None:
                        desiredCursor = Cursors.Arrow;
                        break;
                    case HitType.Body:
                        desiredCursor = Cursors.ScrollAll;
                        break;
                    case HitType.UL:
                    case HitType.LR:
                        desiredCursor = Cursors.SizeNWSE;
                        break;
                    case HitType.LL:
                    case HitType.UR:
                        desiredCursor = Cursors.SizeNESW;
                        break;
                    case HitType.T:
                    case HitType.B:
                        desiredCursor = Cursors.SizeNS;
                        break;
                    case HitType.L:
                    case HitType.R:
                        desiredCursor = Cursors.SizeWE;
                        break;
                }
    
                if (Cursor != desiredCursor) Cursor = desiredCursor;
            }
    
            private void canvas1_MouseDown(object sender, MouseButtonEventArgs e)
            {
                MouseHitType = SetHitType(rectangle1, e.GetPosition(canvas1));
                SetMouseCursor();
                if (MouseHitType == HitType.None) return;
    
                LastPoint = e.GetPosition(canvas1);
                DragInProgress = true;
            }
    
            private void canvas1_MouseMove(object sender, MouseEventArgs e)
            {
                if (DragInProgress)
                {
                    Point point = e.GetPosition(canvas1);
                    double offsetX = point.X - LastPoint.X;
                    double offsetY = point.Y - LastPoint.Y;
    
                    double newX = Canvas.GetLeft(rectangle1);
                    double newY = Canvas.GetTop(rectangle1);
                    double newWidth = rectangle1.Width;
                    double newHeight = rectangle1.Height;
    
                    switch (MouseHitType)
                    {
                        case HitType.Body:
                            newX += offsetX;
                            newY += offsetY;
                            break;
                        case HitType.UL:
                            newX += offsetX;
                            newY += offsetY;
                            newWidth -= offsetX;
                            newHeight -= offsetY;
                            break;
                        case HitType.UR:
                            newY += offsetY;
                            newWidth += offsetX;
                            newHeight -= offsetY;
                            break;
                        case HitType.LR:
                            newWidth += offsetX;
                            newHeight += offsetY;
                            break;
                        case HitType.LL:
                            newX += offsetX;
                            newWidth -= offsetX;
                            newHeight += offsetY;
                            break;
                        case HitType.L:
                            newX += offsetX;
                            newWidth -= offsetX;
                            break;
                        case HitType.R:
                            newWidth += offsetX;
                            break;
                        case HitType.B:
                            newHeight += offsetY;
                            break;
                        case HitType.T:
                            newY += offsetY;
                            newHeight -= offsetY;
                            break;
                    }
    
                    if ((newWidth > 0) && (newHeight > 0))
                    {
                        Canvas.SetLeft(rectangle1, newX);
                        Canvas.SetTop(rectangle1, newY);
                        rectangle1.Width = newWidth;
                        rectangle1.Height = newHeight;
                        LastPoint = point;
                    }
                }
                else
                {
                    MouseHitType = SetHitType(rectangle1, e.GetPosition(canvas1));
                    SetMouseCursor();
                }
            }
    
            private void canvas1_MouseUp(object sender, MouseButtonEventArgs e)
            {
                DragInProgress = false;
            }
        }
    }
    
    

    היה מעניין אבל מרגיש לי קצת בזבוז זמן. שוין.

    תכנות

  • שאלה בwpf האם יש דרך להסיר את הצל שסביב האובייקט window
    pcinfogmachP pcinfogmach

    @קומפיונט כתב בשאלה בwpf האם יש דרך להסיר את הצל שסביב האובייקט window:

    חלון קלאסי מקבל את העיטורים והלחצנים (של ה'סגור', 'מזער' וכו') ממערכת ההפעלה, זה משתנה בין מערכות הפעלה וזה כולל גם את הצל שמסביב, אם אתה רוצה חלון ללא עיטורים תגדיר את WindowStyle ל - None, בכזה מקרה תקבל מלבן לבן בלי שם דברים מסביב.

    לא עזר בשביל הצל רק לשאר הדברים
    צריך לעשות גם AllowsTransparency = true;
    כמו ש@קומפיונט כתב
    אבל מסתבר שאם עושים את זה אז מאבדים את היכולת לשנות את הגודל של החלון.

    תכנות

  • תורת אמת בוורד - עכשיו בvsto
    pcinfogmachP pcinfogmach

    @חגי
    כן האינדקס נמצא בתיקייה בתוך התיקייה ToratEmetInWord
    אפשר להעתיק תיקייה זו למחשב אחר
    רק לשים לב שהתיקייה תהיה באותו מיקום כמו תיקיית המקור של תורת אמת (ToratEmetInstall) (כרגיל המיקום שלו זה תיקיית המסמכים שלי).

    תוכנה

  • עזרה בקוד C# wpf
    pcinfogmachP pcinfogmach

    @dovid
    לא הסברתי את שאלתי בצורה מספיק ברורה. סליחה.
    בקוד הנ"ל הוספתי תכונה ליוזר פורם שאפשר להוזיז אותו (זה נמצא בclass של היוזרפורם).
    ועוד תכונה (בclass נפרד) שכאשר המשתמש מתחיל להזיז את היוזרפורם אז מופיעים ארבעה כפתורים באיזור של העכבר (התפקיד של הכפתורים הוא להצמיד את היוזר פורם לאחד מן הצדדים של החלון המרכזי אם המתשמש עוזב את העכבר כאשר הוא מעל אחד מהכפתורים).
    המראה של הכפתורים אמור להיות ככה:
    bd2042ed-f110-49f0-b1ba-561bdcc37e7c-image.png
    אבל זה משתבש לי בפעם הראשונה שמשתמש לוחץ על היוזר פורם
    219a2221-5b81-4b76-bb2b-1cbea67a8620-image.png
    כמו שאתה רואים הכפתורים לא מופיעים כמו שרציתי. - משום מה זה קורה רק בפעם הראשונה ואני לא מצליח להבין למה.

    תכנות

  • שאלה בwpf האם יש דרך להסיר את הצל שסביב האובייקט window
    pcinfogmachP pcinfogmach

    שאלה בwpf האם יש דרך להסיר את הצל שסביב האובייקט window

    תכנות

  • איך ליצור childform יותר יפה כאשר משתמשים בmdi
    pcinfogmachP pcinfogmach

    @dovid כתב באיך ליצור childform יותר יפה כאשר משתמשים בmdi:

    תבדוק את זה:
    https://github.com/Dirkster99/AvalonDock

    בדקתי
    הוא מושלם תודה.

    תכנות

  • עזרה בקוד C# wpf
    pcinfogmachP pcinfogmach

    עשיתי קוד שיוצר תכונת snap על ידי כפתורים דינמיים עבור usercontrol בwpf
    נתקלתי בבעיה שבפעם הרשונה שהכפתורים נטענים המיקום שלהם משובש.

    מצו:ב הקוד

    <UserControl x:Class="test_wpf_snap.UserControl3"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 mc:Ignorable="d" 
                 MouseLeftButtonDown="UserControl_MouseLeftButtonDown"
                 MouseMove="UserControl_MouseMove"
                 MouseLeftButtonUp="UserControl_MouseLeftButtonUp"
                 BorderBrush="Black" 
                 d:DesignHeight="100" d:DesignWidth="100">
    
        <UserControl.Background>
            <SolidColorBrush Color="{DynamicResource {x:Static SystemColors.ControlColorKey}}"/>
        </UserControl.Background>
        <Grid Width="100" Height="100">
            <Grid.RowDefinitions>
                <RowDefinition Height="25"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
    
            <ToolBar Grid.Row="0">
    
            </ToolBar>
            <DockPanel >
                <DockPanel.Background>
                    <SolidColorBrush Color="{DynamicResource {x:Static SystemColors.WindowColorKey}}"/>
                </DockPanel.Background>
    
                <Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
          Content="X" Width="25"  DockPanel.Dock="Right" HorizontalAlignment="Right"/>
    
            </DockPanel>
        </Grid>
    </UserControl>
    
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    
    
    namespace test_wpf_snap
    {
        /// <summary>
        /// Interaction logic for UserControl3.xaml
        /// </summary>
        public partial class UserControl3 : UserControl
        {
            private bool inDrag = false;
            private Point anchorPoint;
            private bool showSnapButtons = false;
            SnapButtons snapButtons;
    
            public UserControl3()
            {
                InitializeComponent();
                snapButtons = new SnapButtons(this);
            }
    
            private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {
                if (!inDrag)
                {
                    anchorPoint = e.GetPosition(null);
                    CaptureMouse();
                    inDrag = true;
    
                    snapButtons.ShowSnapButtons();
    
                    e.Handled = true;
                }
            }
    
            private void UserControl_MouseMove(object sender, MouseEventArgs e)
            {           
                if (inDrag)
                {
                    Point currentPoint = e.GetPosition(null);
    
                    // Move the UserControl
                    Canvas.SetLeft(this, Canvas.GetLeft(this) + (currentPoint.X - anchorPoint.X));
                    Canvas.SetTop(this, Canvas.GetTop(this) + (currentPoint.Y - anchorPoint.Y));
                    anchorPoint = currentPoint;
    
                    snapButtons.HighlightSnapButtonIfMouseOver(snapButtons.snapTopButton, e);
                    snapButtons.HighlightSnapButtonIfMouseOver(snapButtons.snapBottomButton, e);
                    snapButtons.HighlightSnapButtonIfMouseOver(snapButtons.snapLeftButton, e);
                    snapButtons.HighlightSnapButtonIfMouseOver(snapButtons.snapRightButton, e);
                }
    
                e.Handled = true;
            }
    
            private void UserControl_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
            {
                if (inDrag)
                {
                    ReleaseMouseCapture();
                    inDrag = false;
    
                    snapButtons.HideSnapButtons();
                    e.Handled = true;
                }
            }
        }
    }
    
    
    using System;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Threading;
    
    namespace test_wpf_snap
    {
        public class SnapButtons
        {
            public Button snapTopButton;
            public Button snapBottomButton;
            public Button snapLeftButton;
            public Button snapRightButton;
            private UserControl snapControl;
            private bool showSnapButtons;
    
            public SnapButtons(UserControl control)
            {
                InitializeSnapButtons();
                snapControl = control;
            }
    
            private void InitializeSnapButtons()
            {
                snapTopButton = CreateSnapButton("Snap\r\nTop", "SnapToTop");
                snapBottomButton = CreateSnapButton("Snap\r\nBottom", "SnapToBottom");
                snapLeftButton = CreateSnapButton("Snap\r\nLeft", "SnapToLeft");
                snapRightButton = CreateSnapButton("Snap\r\nRight", "SnapToRight");
    
                HideSnapButtons();
            }
    
            private Button CreateSnapButton(string buttonText, string tag)
            {
                var button = new Button { Content = CreateCenteredTextBlock(buttonText), Tag = tag };
                SetButtonStyle(button);
                return button;
            }
    
            private TextBlock CreateCenteredTextBlock(string text)
            {
                var textBlock = new TextBlock
                {
                    FontSize = 9,
                    Text = text,
                    TextAlignment = TextAlignment.Center,
                    VerticalAlignment = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Stretch
                };
    
                return textBlock;
            }
    
            private void SetButtonStyle(Button button)
            {
                button.Background = Brushes.Transparent;
                button.Foreground = Brushes.Black;
    
                button.Width = 30;
                button.Height = 30;
    
                button.MouseEnter += (sender, e) => SnapToPosition((Button)sender);
            }
    
            private void SnapToPosition(Button button)
            {
                double targetLeft = Canvas.GetLeft(snapControl);
                double targetTop = Canvas.GetTop(snapControl);
    
                switch (button.Tag.ToString())
                {
                    case "SnapToTop":
                        targetTop = 0;
                        break;
                    case "SnapToBottom":
                        targetTop = ((Canvas)snapControl.Parent).ActualHeight - snapControl.ActualHeight;
                        break;
                    case "SnapToLeft":
                        targetLeft = 0;
                        break;
                    case "SnapToRight":
                        targetLeft = ((Canvas)snapControl.Parent).ActualWidth - snapControl.ActualWidth;
                        break;
                }
    
                Canvas.SetLeft(snapControl, targetLeft);
                Canvas.SetTop(snapControl, targetTop);
            }
    
            public void HighlightSnapButtonIfMouseOver(Button button, MouseEventArgs e)
            {
                Point mousePosition = e.GetPosition(button);
    
                if (mousePosition.X >= 0 && mousePosition.X <= button.ActualWidth &&
                    mousePosition.Y >= 0 && mousePosition.Y <= button.ActualHeight)
                {
                    // Use system default highlight color
                    button.Background = SystemColors.ActiveCaptionBrush;
                }
                else
                {
                    // Remove highlighting if the mouse is not over the button
                    button.Background = Brushes.Transparent;
                }
            }
    
            public void ShowSnapButtons()
            {
                if (showSnapButtons)
                    return;
    
                Canvas canvas = snapControl.Parent as Canvas;
                if (canvas == null)
                    return;
    
                double centerX = Canvas.GetLeft(snapControl) + snapControl.ActualWidth / 2;
                double centerY = Canvas.GetTop(snapControl) + snapControl.ActualHeight / 2;
    
                double buttonSeparation = 10;
    
                // Set the position of the imaginary center button
                SetSnapButtonPosition(snapBottomButton, centerX, centerY);
    
                // Adjust other buttons relative to the imaginary center button
                SetSnapButtonPosition(snapTopButton, centerX, centerY - snapTopButton.ActualHeight - buttonSeparation);
                SetSnapButtonPosition(snapLeftButton, centerX - snapLeftButton.ActualWidth - buttonSeparation, centerY);
                SetSnapButtonPosition(snapRightButton, centerX + snapBottomButton.ActualWidth + buttonSeparation, centerY);
    
                // Apply styles and add buttons to the canvas
                foreach (Button button in new[] { snapTopButton, snapBottomButton, snapLeftButton, snapRightButton })
                {
                    canvas.Children.Add(button);
                }
    
                showSnapButtons = true;
            }
    
            private void SetSnapButtonPosition(Button button, double left, double top)
            {
                Canvas.SetLeft(button, left - button.ActualWidth / 2);
                Canvas.SetTop(button, top - button.ActualHeight / 2);
            }
    
            public void HideSnapButtons()
            {
                if (showSnapButtons)
                {
                    // Remove snap buttons from the Canvas
                    Canvas canvas = snapControl.Parent as Canvas;
                    canvas?.Children.Remove(snapTopButton);
                    canvas?.Children.Remove(snapBottomButton);
                    canvas?.Children.Remove(snapLeftButton);
                    canvas?.Children.Remove(snapRightButton);
    
                    showSnapButtons = false;
                }
            }
        }
    }
    
    
    תכנות

  • האם יש צורה לסדר קבצים בסייר של חלונות בלי למספר אותם?
    pcinfogmachP pcinfogmach

    האם יש צורה לסדר קבצים בסייק של חלונות בלי למספר אותם
    לדוגמא אם יש לי את הקבצים
    בראשית
    שמות
    ויקרא
    במדבר
    דברים

    גומלין - כללי

  • מה ההבדל בין שני סוגי הפרויקטים הללו בויז'ואל סטודיו?
    pcinfogmachP pcinfogmach

    @קומפיונט כתב במה ההבדל בין שני סוגי הפרויקטים הללו בויז'ואל סטודיו?:

    אפשר לשאול הפוך: מה היתרון לפתח ב net framework?

    ב net framework בעיקרון בגלל שהוא יותר ותיק יש פקדים שאין ב.net core.

    הכל תלוי בצרכים. כדאי לבדוק מראש שיש את הפקדים שאתה צריך.

    תכנות

  • יצירת קובץ exe יחיד לאחר הקימפול בויזו'אל סטודיו
    pcinfogmachP pcinfogmach

    @מוטי-מן
    תבדוק בnuget את Costura.Fody בעבר השתמשתי איתו כעת לא בדקתי מספיק. אבל הוא אמור ליצור תוכנה ניידת.
    אחרי ההתקנה שלו יש ללחוץ על build ואז אתה מקבל exe מוכן להפצה בתיקיית הbin > debug
    שים לב שהוא עלול לדפוק את האפשרות של debug מתוך vs
    שים לב - אנטי וירוסים לא כל כך אוהבים תוכנות מסוג כזה

    תכנות

  • תורת אמת בוורד - עכשיו בvsto
    pcinfogmachP pcinfogmach

    @פלורידה

    2
    3
    תוקן

    1
    בבדיקה

    תודה

    תוכנה

  • בעיה עם הפקד webview בC# winforms
    pcinfogmachP pcinfogmach

    נתקלתי בבעיה עם הפקד wbeview2 כאשר יש כמה controls אז הוא לא מצליח להיטען. אשמח לכל עזרה
    בפרוייקט שלי יש
    חלון ראשי
    בחלון הראשי יש
    splitcontainer
    ו- toolstrip
    בתוך panel2 אני מעלה userform עם webview2 וזה לא עולה

    תכנות

  • שאלה בVsto בC# איך אפשר להוסיף תמיכה לתוסף שלי עבור דארק מוד
    pcinfogmachP pcinfogmach

    שאלה בVsto בC# איך אפשר להוסיף תמיכה לתוסף שלי עבור דארק מוד

    ככה אמור להיראות

    https://tchumim.com/assets/uploads/files/1700939066142-c195b348-15d4-4c4b-9169-6ea38a38fafc-86d02530-38cc-414b-ae1f-6ad53e4667a8-image.png

    וככה זה נראה בדארק מוד. (מה שמפריע בפרט זה שהלחצנים ליד תיבת החיפוש לא ניראים).

    https://tchumim.com/assets/uploads/files/1700940365410-47b5af8c-b452-4c89-9aad-3255e8a3bab0-תמונה.png

    תכנות

  • תורת אמת בוורד - עכשיו בvsto
    pcinfogmachP pcinfogmach

    תוסף חדש לוורד - תורת אמת בוורד
    המאגר התורני החינמי בתוך וורד
    להורדת התוסף לחץ כאן
    לפני החילוץ של הקובץ לחץ לחיצה ימנית על הקובץ והסר חסימה אינטרנטית
    באפשרויות הקובץ

    כדי להשתמש בתוסף יש להתקין את תורת אמת במחשב. להריץ את התוכנה כמנהל מערכת לכה"פ פעם אחת.

    תודה מיוחדת ל:
    @האדם-החושב
    @dovid
    שעזרו רבות בבניית התוסף.

    הערה: קיצור מקשים Cntrl + T אמור להעביר את הפוקוס חזרה למסמך הפתוח (לא תמיד עובד תלוי אם הפוקוס באמת נמצא בתוך התוסף או לא).

    9c37f203-9f65-4ccb-9068-07de894625b4-e608d29f-2af6-4c0c-9b13-1df6a06e4408-image.png
    51bd67fe-11e9-4e97-8065-094c743852e7-d740219e-d027-401c-813f-3f7b2c3f070b-image.png
    c195b348-15d4-4c4b-9169-6ea38a38fafc-86d02530-38cc-414b-ae1f-6ad53e4667a8-image.png

    תוכנה

  • איך ליצור childform יותר יפה כאשר משתמשים בmdi
    pcinfogmachP pcinfogmach

    שיחקתי עם זה קצת והוספתי לו תכונות snap פשוטות (לקצוות של הparentform ולקצוות של אחד לשני)

    static class MyDictionary
    {
        public static List<SizeableUserControl> userControlCollection = new List<SizeableUserControl>();
    }
    
    class SizeableUserControl : UserControl
    {
        Form parentForm;
        private const int grab = 16;
        public SizeableUserControl(Form form)
        {
            parentForm = form;
            MyDictionary.userControlCollection.Add(this);
            this.ResizeRedraw = true;
            InitializeComponent();
        }
    
        private void InitializeComponent()
        {
            this.SuspendLayout();
            this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.Name = "SizeableUserControl";
            this.Size = new System.Drawing.Size(100, 100);
            
            Panel titleBar = new Panel();
            titleBar.Dock = DockStyle.Top;
            titleBar.BackColor = Color.White;
    
            titleBar.Height = 20;
            Controls.Add(titleBar);
            titleBar.MouseDown += TitleBar_MouseDown;
            titleBar.MouseMove += TitleBar_MouseMove;
            titleBar.MouseUp += TitleBar_MouseUp;
    
            // Minimize button
            Button minimizeButton = new Button();
            minimizeButton.Text = "─";
            minimizeButton.TextAlign = ContentAlignment.MiddleCenter;
            minimizeButton.Width = 20;
            minimizeButton.Height = 20;
            minimizeButton.Dock = DockStyle.Right;
            minimizeButton.FlatStyle = FlatStyle.Flat;
            minimizeButton.FlatAppearance.BorderSize = 0;
            titleBar.Controls.Add(minimizeButton);
    
            minimizeButton.Click += (sender, e) =>
            {
                if (minimizeButton.Text == "─")
                { 
                minimizeButton.Text = "+";
                this.Height = 20;
                this.Width = 60;
                }
                else
                {
                    minimizeButton.Text = "─";
                    this.Height = 100;
                    this.Width = 100;
                }
            };
    
            // Maximize button
            Button maximizeButton = new Button();
            maximizeButton.Text = "⬜"; // Larger square Unicode character
            maximizeButton.TextAlign = ContentAlignment.MiddleCenter;
            maximizeButton.Width = 20;
            maximizeButton.Height = 20;
            maximizeButton.Dock = DockStyle.Right;
            maximizeButton.FlatStyle = FlatStyle.Flat;
            maximizeButton.FlatAppearance.BorderSize = 0;
    
            // Store the original DockStyle
            DockStyle originalDockStyle = DockStyle.None;
    
            maximizeButton.Click += (sender, e) =>
            {
                if (this.Dock == DockStyle.None)
                {
                    // Maximize the form
                    originalDockStyle = this.Dock;
                    this.Dock = DockStyle.Fill;
                    maximizeButton.Text = "❐"; // Change text to indicate restore
                }
                else
                {
                    // Restore the original DockStyle
                    this.Dock = originalDockStyle;
                    maximizeButton.Text = "⬜"; // Change text to indicate maximize
                }
            };
    
            titleBar.Controls.Add(maximizeButton);
    
    
            // X button
            Button xButton = new Button();
            xButton.Text = "X";
            xButton.Dock = DockStyle.Right;
            xButton.Width = 20;
            xButton.Height = 20;
            xButton.FlatStyle = FlatStyle.Flat;
            xButton.FlatAppearance.BorderSize = 0;
            xButton.Click += (sender, e) => this.Dispose();
            titleBar.Controls.Add(xButton);
    
            this.ResumeLayout(false);
        }
    
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            const int WM_NCHITTEST = 0x84;
            const int HT_LEFT = 10;
            const int HT_RIGHT = 11;
            const int HT_TOP = 12;
            const int HT_TOPLEFT = 13;
            const int HT_TOPRIGHT = 14;
            const int HT_BOTTOM = 15;
            const int HT_BOTTOMLEFT = 16;
            const int HT_BOTTOMRIGHT = 17;
    
            if (m.Msg == WM_NCHITTEST)
            {
                var pos = this.PointToClient(new Point(m.LParam.ToInt32()));
    
                if (pos.X <= grab && pos.Y <= grab)
                    m.Result = new IntPtr(HT_TOPLEFT);
                else if (pos.X >= this.ClientSize.Width - grab && pos.Y <= grab)
                    m.Result = new IntPtr(HT_TOPRIGHT);
                else if (pos.X <= grab && pos.Y >= this.ClientSize.Height - grab)
                    m.Result = new IntPtr(HT_BOTTOMLEFT);
                else if (pos.X >= this.ClientSize.Width - grab && pos.Y >= this.ClientSize.Height - grab)
                    m.Result = new IntPtr(HT_BOTTOMRIGHT);
                else if (pos.X <= grab)
                    m.Result = new IntPtr(HT_LEFT);
                else if (pos.X >= this.ClientSize.Width - grab)
                    m.Result = new IntPtr(HT_RIGHT);
                else if (pos.Y <= grab)
                    m.Result = new IntPtr(HT_TOP);
                else if (pos.Y >= this.ClientSize.Height - grab)
                    m.Result = new IntPtr(HT_BOTTOM);
            }
        }
    
    
    
        bool isMouseDown = false;
        private Point mouseDownLocation;
    
        private void TitleBar_MouseUp(object sender, MouseEventArgs e)
        {
            isMouseDown = false;
        }
    
        private void TitleBar_MouseMove(object sender, MouseEventArgs e)
        {
            if (isMouseDown)
            {
                // Check proximity on all sides (adjust the threshold as needed)
                int proximityThreshold = 10;
    
                // Calculate the new position of the control based on the mouse movement
                int newX = this.Left - mouseDownLocation.X + e.X;
                int newY = this.Top - mouseDownLocation.Y + e.Y;
    
                // Ensure the new position is within the boundaries of the parent form
                newX = Math.Max(0, Math.Min(newX, parentForm.ClientSize.Width - this.Width));
                newY = Math.Max(0, Math.Min(newY, parentForm.ClientSize.Height - this.Height));
    
                // Iterate through other controls and check if snapping is possible
                foreach (var kvp in MyDictionary.userControlCollection)
                {
                    if (kvp != this)
                    {
                        // Check top side
                        if (Math.Abs(newY - kvp.Bottom) < proximityThreshold)
                        {
                            newY = kvp.Bottom + 1;
    
                            // Align right and left if they are close enough
                            if (Math.Abs(newX - kvp.Left) < proximityThreshold)
                            {
                                newX = kvp.Left;
                            }
                            else if (Math.Abs(newX + this.Width - kvp.Right) < proximityThreshold)
                            {
                                newX = kvp.Right - this.Width;
                            }
                        }
    
                        // Check bottom side
                        else if (Math.Abs(newY + this.Height - kvp.Top) < proximityThreshold)
                        {
                            newY = kvp.Top - this.Height - 1;
    
                            // Align right and left if they are close enough
                            if (Math.Abs(newX - kvp.Left) < proximityThreshold)
                            {
                                newX = kvp.Left;
                            }
                            else if (Math.Abs(newX + this.Width - kvp.Right) < proximityThreshold)
                            {
                                newX = kvp.Right - this.Width;
                            }
                        }
    
                        // Check left side
                        if (Math.Abs(newX - kvp.Right) < proximityThreshold)
                        {
                            newX = kvp.Right + 1;
    
                            // Align tops if they are close enough
                            if (Math.Abs(newY - kvp.Top) < proximityThreshold)
                            {
                                newY = kvp.Top;
                            }
                            // Align bottoms if they are close enough
                            else if (Math.Abs(newY + this.Height - kvp.Bottom) < proximityThreshold)
                            {
                                newY = kvp.Bottom - this.Height;
                            }
                        }
    
                        // Check right side
                        else if (Math.Abs(newX + this.Width - kvp.Left) < proximityThreshold)
                        {
                            newX = kvp.Left - this.Width - 1;
    
                            // Align tops if they are close enough
                            if (Math.Abs(newY - kvp.Top) < proximityThreshold)
                            {
                                newY = kvp.Top;
                            }
                            // Align bottoms if they are close enough
                            else if (Math.Abs(newY + this.Height - kvp.Bottom) < proximityThreshold)
                            {
                                newY = kvp.Bottom - this.Height;
                            }
                        }
                    }
                }
    
                // Snap to parent form edges
                if (Math.Abs(newX) < proximityThreshold)
                {
                    newX = 0;
                }
                else if (Math.Abs(newX + this.Width - parentForm.ClientSize.Width) < proximityThreshold)
                {
                    newX = parentForm.ClientSize.Width - this.Width;
                }
    
                if (Math.Abs(newY) < proximityThreshold)
                {
                    newY = 0;
                }
                else if (Math.Abs(newY + this.Height - parentForm.ClientSize.Height) < proximityThreshold)
                {
                    newY = parentForm.ClientSize.Height - this.Height;
                }
    
                this.Location = new Point(newX, newY);
    
                // Forces the control to repaint for a smoother visual experience
                this.Invalidate();
            }
        }
    
    
    
        
    
        private void TitleBar_MouseDown(object sender, MouseEventArgs e)
        {
            isMouseDown = true;
            mouseDownLocation = e.Location;
        }
    }
    
    תכנות

  • איך ליצור childform יותר יפה כאשר משתמשים בmdi
    pcinfogmachP pcinfogmach

    לבינתיים השלמתי את המלאכה בwinform אולי יהיה שימושי למישהו

    c9c8cd46-4e3f-40d4-a126-47b877024225-image.png

    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace ResizableTextBox
    {
        class SizeableUserControl : UserControl
        {
            private const int grab = 16;
    
            public SizeableUserControl()
            {
                this.ResizeRedraw = true;
                InitializeComponent();
            }
    
            protected override void WndProc(ref Message m)
            {
                base.WndProc(ref m);
                const int WM_NCHITTEST = 0x84;
                const int HT_LEFT = 10;
                const int HT_RIGHT = 11;
                const int HT_TOP = 12;
                const int HT_TOPLEFT = 13;
                const int HT_TOPRIGHT = 14;
                const int HT_BOTTOM = 15;
                const int HT_BOTTOMLEFT = 16;
                const int HT_BOTTOMRIGHT = 17;
    
                if (m.Msg == WM_NCHITTEST)
                {
                    var pos = this.PointToClient(new Point(m.LParam.ToInt32()));
    
                    if (pos.X <= grab && pos.Y <= grab)
                        m.Result = new IntPtr(HT_TOPLEFT);
                    else if (pos.X >= this.ClientSize.Width - grab && pos.Y <= grab)
                        m.Result = new IntPtr(HT_TOPRIGHT);
                    else if (pos.X <= grab && pos.Y >= this.ClientSize.Height - grab)
                        m.Result = new IntPtr(HT_BOTTOMLEFT);
                    else if (pos.X >= this.ClientSize.Width - grab && pos.Y >= this.ClientSize.Height - grab)
                        m.Result = new IntPtr(HT_BOTTOMRIGHT);
                    else if (pos.X <= grab)
                        m.Result = new IntPtr(HT_LEFT);
                    else if (pos.X >= this.ClientSize.Width - grab)
                        m.Result = new IntPtr(HT_RIGHT);
                    else if (pos.Y <= grab)
                        m.Result = new IntPtr(HT_TOP);
                    else if (pos.Y >= this.ClientSize.Height - grab)
                        m.Result = new IntPtr(HT_BOTTOM);
                }
            }
    
            private void InitializeComponent()
            {
                this.SuspendLayout();
                this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                this.Name = "SizeableUserControl";
                this.Size = new System.Drawing.Size(100, 100);
                
                Panel titleBar = new Panel();
                titleBar.Dock = DockStyle.Top;
                titleBar.BackColor = Color.White;
    
                titleBar.Height = 20;
                Controls.Add(titleBar);
                titleBar.MouseDown += TitleBar_MouseDown;
                titleBar.MouseMove += TitleBar_MouseMove;
                titleBar.MouseUp += TitleBar_MouseUp;
    
                // Minimize button
                Button minimizeButton = new Button();
                minimizeButton.Text = "─";
                minimizeButton.TextAlign = ContentAlignment.MiddleCenter;
                minimizeButton.Width = 20;
                minimizeButton.Height = 20;
                minimizeButton.Dock = DockStyle.Right;
                minimizeButton.FlatStyle = FlatStyle.Flat;
                minimizeButton.FlatAppearance.BorderSize = 0;
                titleBar.Controls.Add(minimizeButton);
    
                minimizeButton.Click += (sender, e) =>
                {
                    if (minimizeButton.Text == "─")
                    { 
                    minimizeButton.Text = "+";
                    this.Height = 20;
                    this.Width = 60;
                    }
                    else
                    {
                        minimizeButton.Text = "─";
                        this.Height = 100;
                        this.Width = 100;
                    }
                };
    
                // Maximize button
                Button maximizeButton = new Button();
                maximizeButton.Text = "⬜"; // Larger square Unicode character
                maximizeButton.TextAlign = ContentAlignment.MiddleCenter;
                maximizeButton.Width = 20;
                maximizeButton.Height = 20;
                maximizeButton.Dock = DockStyle.Right;
                maximizeButton.FlatStyle = FlatStyle.Flat;
                maximizeButton.FlatAppearance.BorderSize = 0;
    
                // Store the original DockStyle
                DockStyle originalDockStyle = DockStyle.None;
    
                maximizeButton.Click += (sender, e) =>
                {
                    if (this.Dock == DockStyle.None)
                    {
                        // Maximize the form
                        originalDockStyle = this.Dock;
                        this.Dock = DockStyle.Fill;
                        maximizeButton.Text = "❐"; // Change text to indicate restore
                    }
                    else
                    {
                        // Restore the original DockStyle
                        this.Dock = originalDockStyle;
                        maximizeButton.Text = "⬜"; // Change text to indicate maximize
                    }
                };
    
                titleBar.Controls.Add(maximizeButton);
    
    
                // X button
                Button xButton = new Button();
                xButton.Text = "X";
                xButton.Dock = DockStyle.Right;
                xButton.Width = 20;
                xButton.Height = 20;
                xButton.FlatStyle = FlatStyle.Flat;
                xButton.FlatAppearance.BorderSize = 0;
                xButton.Click += (sender, e) => this.Dispose();
                titleBar.Controls.Add(xButton);
    
                this.ResumeLayout(false);
            }
    
            bool isMouseDown = false;
            private Point mouseDownLocation;
    
            private void TitleBar_MouseUp(object sender, MouseEventArgs e)
            {
                isMouseDown = false;
            }
    
            private void TitleBar_MouseMove(object sender, MouseEventArgs e)
            {
                if (isMouseDown)
                {
                    if (isMouseDown)
                    {
                        // Calculate the new position of the form based on the mouse movement
                        this.Location = new Point(
                            (this.Location.X - mouseDownLocation.X) + e.X,
                            (this.Location.Y - mouseDownLocation.Y) + e.Y);
    
                        this.Update(); // Forces the form to repaint for a smoother visual experience
                    }
                }
            }
    
            private void TitleBar_MouseDown(object sender, MouseEventArgs e)
            {
                isMouseDown = true;
                mouseDownLocation = e.Location;
            }
        }
    }
    
    
    תכנות

  • איך ליצור childform יותר יפה כאשר משתמשים בmdi
    pcinfogmachP pcinfogmach

    הבעיה שנסיון לעשות כזה דבר בwpf עלה לי ממש בתוהו פה לפחות הגעתי לאן שהוא
    עריכה:
    עכשיו ראיתי את זה בwpf צריך לשבת לראות מה יצא
    http://csharphelper.com/howtos/howto_wpf_resize_rectangle.html

    תכנות

  • איך ליצור childform יותר יפה כאשר משתמשים בmdi
    pcinfogmachP pcinfogmach

    מסתבר שאפשר להשתמש עם usercontrol
    הנה משהו בתור התחלה אזמח אם מישהו יוכל לעבור על זה ואולי גם לעזור לי לשפר את זה - נתקעתי עם הרחבה בצד שמאל ולמעלה - ועם כפתור minimize

    using System;
    using System.Drawing;
    using System.Windows.Forms;
    
    namespace TestC
    {
        public partial class Form1 : Form
        {
            private ResizeableControl resizeableControl;
    
            public Form1()
            {
                InitializeComponent();
                InitializeResizeableControl();
            }
    
            private void InitializeResizeableControl()
            {
                resizeableControl = new ResizeableControl();
                Controls.Add(resizeableControl);
    
                // Handle the Resize event of the form to update the size of the control
                Resize += (sender, e) => resizeableControl.Size = ClientSize;
            }
        }
    
        public class ResizeableControl : UserControl
        {
            private const int BorderSize = 8;
            private bool isResizing = false;
            private bool isResizingHorizontal = false;
            private bool isResizingVertical = false;
            private Point lastMousePosition;
    
            bool isMouseDown = false;
            private Point mouseDownLocation;
    
            public ResizeableControl()
            {
                // Set the initial size
                Size = new Size(200, 200);
                BorderStyle = BorderStyle.FixedSingle;
                // Handle mouse events
                MouseDown += OnMouseDown;
                MouseMove += OnMouseMove;
                MouseUp += OnMouseUp;
                InitializeComponents();
            }
    
            private void InitializeComponents()
            {
                Panel titleBar = new Panel();
                titleBar.Dock = DockStyle.Top;
                titleBar.BackColor = Color.White;
    
                titleBar.Height = 20;
                Controls.Add(titleBar);
                titleBar.MouseDown += TitleBar_MouseDown;
                titleBar.MouseMove += TitleBar_MouseMove;
                titleBar.MouseUp += TitleBar_MouseUp;
    
                // Maximize button
                Button maximizeButton = new Button();
                maximizeButton.Text = "⬜"; // Larger square Unicode character
                maximizeButton.Width = 20;
                maximizeButton.Height = 20;
                maximizeButton.Dock = DockStyle.Right;
                maximizeButton.FlatStyle = FlatStyle.Flat;
                maximizeButton.FlatAppearance.BorderSize = 0;
    
                // Store the original DockStyle
                DockStyle originalDockStyle = DockStyle.None;
    
                maximizeButton.Click += (sender, e) =>
                {
                    if (this.Dock == DockStyle.None)
                    {
                        // Maximize the form
                        originalDockStyle = this.Dock;
                        this.Dock = DockStyle.Fill;
                        maximizeButton.Text = "❐"; // Change text to indicate restore
                    }
                    else
                    {
                        // Restore the original DockStyle
                        this.Dock = originalDockStyle;
                        maximizeButton.Text = "□"; // Change text to indicate maximize
                    }
                };
    
                titleBar.Controls.Add(maximizeButton);
    
    
                // X button
                Button xButton = new Button();
                xButton.Text = "X";
                xButton.Dock = DockStyle.Right;
                xButton.Width = 20;
                xButton.Height = 20;
                xButton.FlatStyle = FlatStyle.Flat;
                xButton.FlatAppearance.BorderSize = 0;
                xButton.Click += (sender, e) => this.Dispose();
                titleBar.Controls.Add(xButton);
            }
    
    
            private void TitleBar_MouseUp(object sender, MouseEventArgs e)
            {
                isMouseDown = false;
            }
    
            private void TitleBar_MouseMove(object sender, MouseEventArgs e)
            {
                if (isMouseDown)
                {
                    if (isMouseDown)
                    {
                        // Calculate the new position of the form based on the mouse movement
                        this.Location = new Point(
                            (this.Location.X - mouseDownLocation.X) + e.X,
                            (this.Location.Y - mouseDownLocation.Y) + e.Y);
    
                        this.Update(); // Forces the form to repaint for a smoother visual experience
                    }
                }
            }
    
            private void TitleBar_MouseDown(object sender, MouseEventArgs e)
            {
                isMouseDown = true;
                mouseDownLocation = e.Location;
            }
    
            private void OnMouseDown(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left && IsOnBorder(e.Location))
                {
                    isResizing = true;
                    lastMousePosition = e.Location;
    
                    isResizingHorizontal = e.X <= BorderSize || e.X >= Width - BorderSize;
                    isResizingVertical = e.Y <= BorderSize || e.Y >= Height - BorderSize;
                }
            }
    
            private void OnMouseMove(object sender, MouseEventArgs e)
            {
                if (isResizing)
                {
                    int deltaX = e.X - lastMousePosition.X;
                    int deltaY = e.Y - lastMousePosition.Y;
    
                    if (isResizingHorizontal && isResizingVertical)
                    {
                        // Diagonal resizing
                        Width += deltaX;
                        Height += deltaY;
                    }
                    else if (isResizingHorizontal)
                    {
                        // Horizontal resizing
                        Width += deltaX;
                    }
                    else if (isResizingVertical)
                    {
                        // Vertical resizing
                        Height += deltaY;
                    }
    
                    lastMousePosition = e.Location;
                }
                else
                {
                    if (IsOnCorner(e.Location))
                    {
                        Cursor = Cursors.SizeNWSE;
                    }
                    else if (e.X >= Width - BorderSize && e.Y >= Height - BorderSize)
                    {
                        // Cursor is in the bottom-right corner, allowing diagonal resizing
                        Cursor = Cursors.SizeNWSE;
                    }
                    else if (e.X >= Width - BorderSize)
                    {
                        // Cursor is on the right border, allowing horizontal resizing
                        Cursor = Cursors.SizeWE;
                    }
                    else if (e.Y >= Height - BorderSize)
                    {
                        // Cursor is on the bottom border, allowing vertical resizing
                        Cursor = Cursors.SizeNS;
                    }
                    else
                    {
                        Cursor = Cursors.Default;
                    }
                }
            }
    
    
            private void OnMouseUp(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    isResizing = false;
                    Cursor = Cursors.Default;
                }
            }
    
            private bool IsOnBorder(Point mouseLocation)
            {
                return mouseLocation.X <= BorderSize || mouseLocation.Y <= BorderSize ||
                       mouseLocation.X >= Width - BorderSize || mouseLocation.Y >= Height - BorderSize;
            }
    
            private bool IsOnCorner(Point mouseLocation)
            {
                return mouseLocation.X <= BorderSize && mouseLocation.Y <= BorderSize ||
                       mouseLocation.X >= Width - BorderSize && mouseLocation.Y >= Height - BorderSize;
            }
        }
    }
    
    תכנות

  • שאלה בc# בvisualstudio: איך משתמשים עם קבצי טקסט שהוספתי לפרוייקט שלי?
    pcinfogmachP pcinfogmach

    ראיתי שיש אפשרות להוסיף תיקיות וגם קבצי טקסט לפרוייקט אבל אני לא מצליח להשתמש בהם אחרי שאני מוסיף אותם. (כי הם לא נכנסנים אוטמטית לתיקיית הדיבאג).
    23610ca4-7f74-4586-83f8-29400ac947f9-image.png

    תכנות

  • שאלה: איך עושים דחיסה לקובץ בודד בC#?
    pcinfogmachP pcinfogmach

    @dovid
    הקוד שלך עשה שגיאה ולכן תיקנתי ואז לא היה שגיאה אולי חסר לי איזהו רפרנס?
    (אגב מה באמת ההבדל בין optimal ל-smallestsize?)

    תכנות
  • 1 / 1
  • התחברות

  • אין לך חשבון עדיין? הרשמה

  • התחברו או הירשמו כדי לחפש.
  • פוסט ראשון
    פוסט אחרון
0
  • דף הבית
  • קטגוריות
  • פוסטים אחרונים
  • משתמשים
  • חיפוש
  • חוקי הפורום