Click here to Skip to main content
14,364,903 members
   

C#

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

Form1
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
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:
_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 21:23
protectorOriginalGriff10-Oct-19 21:23 
GeneralRe: Resize controls at runtime (borderless form) Pin
Member 1407482711-Oct-19 2:24
memberMember 1407482711-Oct-19 2:24 
AnswerRe: Resize controls at runtime (borderless form) Pin
Eddy Vluggen11-Oct-19 2:29
mveEddy Vluggen11-Oct-19 2:29 
GeneralRe: Resize controls at runtime (borderless form) Pin
Member 1407482711-Oct-19 3:25
memberMember 1407482711-Oct-19 3:25 
GeneralRe: Resize controls at runtime (borderless form) Pin
Eddy Vluggen11-Oct-19 3:29
mveEddy Vluggen11-Oct-19 3:29 
GeneralRe: Resize controls at runtime (borderless form) Pin
Rob Philpott11-Oct-19 4:03
memberRob Philpott11-Oct-19 4:03 
GeneralRe: Resize controls at runtime (borderless form) Pin
Eddy Vluggen11-Oct-19 4:07
mveEddy Vluggen11-Oct-19 4:07 
AnswerRe: Resize controls at runtime (borderless form) Pin
BillWoodruff21-Oct-19 4:49
mveBillWoodruff21-Oct-19 4:49 
Question2D Arrays Pin
LilJokez_Gaming10-Oct-19 12:27
memberLilJokez_Gaming10-Oct-19 12:27 
AnswerRe: 2D Arrays Pin
Luc Pattyn10-Oct-19 14:11
professionalLuc Pattyn10-Oct-19 14:11 
QuestionHelp with WMI Connect Remotely Pin
mniceguy819-Oct-19 5:30
membermniceguy819-Oct-19 5:30 
AnswerRe: Help with WMI Connect Remotely Pin
Dave Kreskowiak9-Oct-19 7:47
mveDave Kreskowiak9-Oct-19 7:47 
GeneralRe: Help with WMI Connect Remotely Pin
mniceguy819-Oct-19 23:28
membermniceguy819-Oct-19 23:28 
AnswerRe: Help with WMI Connect Remotely Pin
Richard MacCutchan9-Oct-19 9:51
protectorRichard MacCutchan9-Oct-19 9:51 
GeneralRe: Help with WMI Connect Remotely Pin
Dave Kreskowiak9-Oct-19 10:09
mveDave Kreskowiak9-Oct-19 10:09 
GeneralRe: Help with WMI Connect Remotely Pin
mniceguy819-Oct-19 10:26
membermniceguy819-Oct-19 10:26 
AnswerRe: Help with WMI Connect Remotely Pin
OriginalGriff9-Oct-19 10:37
protectorOriginalGriff9-Oct-19 10: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.