Click here to Skip to main content
15,891,708 members
Home / Discussions / C#
   

C#

 
QuestionSystem.NullReferenceException Pin
Alrzini14-Oct-19 10:09
Alrzini14-Oct-19 10:09 
AnswerRe: System.NullReferenceException Pin
OriginalGriff14-Oct-19 10:16
mveOriginalGriff14-Oct-19 10:16 
QuestionHelp with getting Monitors (Screen) information Pin
mniceguy8114-Oct-19 6:35
mniceguy8114-Oct-19 6:35 
AnswerRe: Help with getting Monitors (Screen) information Pin
Dave Kreskowiak14-Oct-19 9:35
mveDave Kreskowiak14-Oct-19 9:35 
GeneralRe: Help with getting Monitors (Screen) information Pin
mniceguy8114-Oct-19 10:42
mniceguy8114-Oct-19 10:42 
GeneralRe: Help with getting Monitors (Screen) information Pin
Dave Kreskowiak14-Oct-19 11:54
mveDave Kreskowiak14-Oct-19 11:54 
GeneralRe: Help with getting Monitors (Screen) information Pin
mniceguy8114-Oct-19 11:56
mniceguy8114-Oct-19 11:56 
QuestionResize controls at runtime (borderless form) Pin
Member 1407482710-Oct-19 15:42
Member 1407482710-Oct-19 15:42 
Maybe someone can help  :)  I can’t figure out how to make this code work for borderless Form

Form1
C#
public partial class Form1 : Form
{
    clsResize _form_resize;

    public Form1()
    {
        InitializeComponent();

        FormBorderStyle = FormBorderStyle.None;
       _form_resize = new clsResize(this);
        this.Load += _Load;
        this.Resize += _Resize;
    }
    private void _Load(object sender, EventArgs e)
    {
        _form_resize._get_initial_size();
    }

    private void _Resize(object sender, EventArgs e)
    {
        _form_resize._resize();
    }
    //
    //This part im using for resize form
    //
    private const int cGrip = 16;

    protected override void OnPaint(PaintEventArgs e)
    {
        Rectangle rc = new Rectangle(ClientSize.Width - cGrip, ClientSize.Height - cGrip, cGrip, cGrip);
        ControlPaint.DrawSizeGrip(e.Graphics, BackColor, rc);
    }

    protected override void WndProc(ref Message m)
    {
        if (m.Msg == 0x84)
        {
            Point pos = new Point(m.LParam.ToInt32());
            pos = PointToClient(pos);
            if (pos.X >= ClientSize.Width - cGrip && pos.Y >= ClientSize.Height - cGrip)
            {
                m.Result = (IntPtr)17;
                return;
            }
        }
        base.WndProc(ref m);
    }

clsResize.cs
C#
public class clsResize
{
    List<System.Drawing.Rectangle> _arr_control_storage = new List<System.Drawing.Rectangle>();
    private bool showRowHeader = false;
    public clsResize(Form _form_)
    {
        form = _form_;
        _formSize = _form_.ClientSize;
        _fontsize = _form_.Font.Size;
    }

    private float _fontsize  { get; set; }

    private System.Drawing.SizeF _formSize {get;set; }

    private Form form { get; set; }

    public void _get_initial_size()
    {
        var _controls = _get_all_controls(form);
        foreach (Control control in _controls)
        {
            _arr_control_storage.Add(control.Bounds);          
        }
    }

    public void _resize()
    {
        double _form_ratio_width = (double)form.ClientSize.Width /(double)_formSize.Width;
        double _form_ratio_height = (double)form.ClientSize.Height / (double)_formSize.Height;
        var _controls = _get_all_controls(form);
        int _pos = -1;
        foreach (Control control in _controls)
        {
            _pos += 1;
            System.Drawing.Size _controlSize = new System.Drawing.Size((int)(_arr_control_storage[_pos].Width * _form_ratio_width),
                (int)(_arr_control_storage[_pos].Height * _form_ratio_height));

            System.Drawing.Point _controlposition = new System.Drawing.Point((int)
            (_arr_control_storage[_pos].X * _form_ratio_width),(int) (_arr_control_storage[_pos].Y * _form_ratio_height));

            control.Bounds = new System.Drawing.Rectangle(_controlposition, _controlSize);

            control.Font = new System.Drawing.Font(form.Font.FontFamily,
             (float)(((Convert.ToDouble(_fontsize) * _form_ratio_width) / 2) +
              ((Convert.ToDouble(_fontsize) * _form_ratio_height) / 2)));

        }
    }
    private static IEnumerable<Control> _get_all_controls(Control c)
    {
        return c.Controls.Cast<Control>().SelectMany(item =>
            _get_all_controls(item)).Concat(c.Controls.Cast<Control>()).Where(control => 
            control.Name != string.Empty);
    }
It works fine when FormBorderStyle.Sizable, but if FormBorderStyle.None get "System ArgumentOutOfRangeException" in this place:
C#
_pos += 1;
System.Drawing.Size _controlSize = new System.Drawing.Size((int)(_arr_control_storage[_pos].Width * _form_ratio_width),
    (int)(_arr_control_storage[_pos].Height * _form_ratio_height));

AnswerRe: Resize controls at runtime (borderless form) Pin
OriginalGriff10-Oct-19 20:23
mveOriginalGriff10-Oct-19 20:23 
GeneralRe: Resize controls at runtime (borderless form) Pin
Member 1407482711-Oct-19 1:24
Member 1407482711-Oct-19 1:24 
AnswerRe: Resize controls at runtime (borderless form) Pin
Eddy Vluggen11-Oct-19 1:29
professionalEddy Vluggen11-Oct-19 1:29 
GeneralRe: Resize controls at runtime (borderless form) Pin
Member 1407482711-Oct-19 2:25
Member 1407482711-Oct-19 2:25 
GeneralRe: Resize controls at runtime (borderless form) Pin
Eddy Vluggen11-Oct-19 2:29
professionalEddy Vluggen11-Oct-19 2:29 
GeneralRe: Resize controls at runtime (borderless form) Pin
Rob Philpott11-Oct-19 3:03
Rob Philpott11-Oct-19 3:03 
GeneralRe: Resize controls at runtime (borderless form) Pin
Eddy Vluggen11-Oct-19 3:07
professionalEddy Vluggen11-Oct-19 3:07 
AnswerRe: Resize controls at runtime (borderless form) Pin
BillWoodruff21-Oct-19 3:49
professionalBillWoodruff21-Oct-19 3:49 
Question2D Arrays Pin
LilJokez_Gaming10-Oct-19 11:27
LilJokez_Gaming10-Oct-19 11:27 
AnswerRe: 2D Arrays Pin
Luc Pattyn10-Oct-19 13:11
sitebuilderLuc Pattyn10-Oct-19 13:11 
QuestionHelp with WMI Connect Remotely Pin
mniceguy819-Oct-19 4:30
mniceguy819-Oct-19 4:30 
AnswerRe: Help with WMI Connect Remotely Pin
Dave Kreskowiak9-Oct-19 6:47
mveDave Kreskowiak9-Oct-19 6:47 
GeneralRe: Help with WMI Connect Remotely Pin
mniceguy819-Oct-19 22:28
mniceguy819-Oct-19 22:28 
AnswerRe: Help with WMI Connect Remotely Pin
Richard MacCutchan9-Oct-19 8:51
mveRichard MacCutchan9-Oct-19 8:51 
GeneralRe: Help with WMI Connect Remotely Pin
Dave Kreskowiak9-Oct-19 9:09
mveDave Kreskowiak9-Oct-19 9:09 
GeneralRe: Help with WMI Connect Remotely Pin
mniceguy819-Oct-19 9:26
mniceguy819-Oct-19 9:26 
AnswerRe: Help with WMI Connect Remotely Pin
OriginalGriff9-Oct-19 9:37
mveOriginalGriff9-Oct-19 9:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.