Hello,
I just started learning this wonderful language! but I m facing some difficulties, which I would like to share, and hope for some help from you guys.

Yesterday while learning I created a program which gets the screen resolution of desktop and displays the form in top-center of screen.
I have written a code but then I get some weird error, and I dont understand it!

"An object reference is required for the nonstatic field, method, or property 'member'"

Please check my code and tell me whats wrong

- Thankyou!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MouseC
{
    
    public partial class form1 : Form
    {
        int deskWidth = Screen.PrimaryScreen.Bounds.Width/2;
        public form1()
        {
            InitializeComponent();
           
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            form1.Location = new Point(deskWidth, 0);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            
        }
    }
}

At what line does it give you the error?

line no. 24

I get red line under form1

for line 24, try:

this.Location = new Point(deskWidth, 0);

@vadriaan

Thankyou!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.