logo
down
shadow

How to use Class.cs in form1


How to use Class.cs in form1

Content Index :

How to use Class.cs in form1
Tag : chash , By : Priyatna Harun
Date : November 28 2020, 12:01 PM

hop of those help? Every function that you want to call from outside your class must be declared with the public accessibility modifier.
From Microsoft's docs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CamTest
{
    class Camera
    {
        public void CboOut_SelectedIndexChanged(object sender, EventArgs e)
        {
            ///Declaration
            int num = cboOut.SelectedIndex;
            cmd = 0x101E;
            len = 0x0001;

            ///Code
            if (num == 0)
            {
                val = 0x03;
            }
            else if (num == 1)
            {
                val = 0x02;
            }
            else if (num == 2)
            {
                val = 0x01;
            }
            else
            {
                val = 0x00;
            }

            ///Pack
            Packs(len, cmd, val);
        }

        public void CboPol_SelectedIndexChanged(object sender, EventArgs e)
        {
            ///Declaration
            int num = cboPol.SelectedIndex;
            len = 0x0000;

            ///Code
            if (num == 0)
            {
                cmd = 0x1030;
            }
            else
            {
                cmd = 0x1031;
            }

            ///Pack
            Packs(len, cmd, val);
        }

        public void CboAmp_SelectedIndexChanged(object sender, EventArgs e)
        {
            ///Declaration
            int num = cboAmp.SelectedIndex;
            len = 0x0000;

            ///Code
            if (num == 0)
            {
                cmd = 0x102A;
            }
            else if (num == 1)
            {
                cmd = 0x102B;
            }
            else if (num == 2)
            {
                cmd = 0x102C;
            }
            else
            {
                cmd = 0x102D;
            }

            ///Pack
            Packs(len, cmd, val);
        }

        public void CboPro_SelectedIndexChanged(object sender, EventArgs e)
        {
            ///Declaration
            int num = cboPro.SelectedIndex;
            len = 0x0000;

            ///Code
            if (num == 0)
            {
                cmd = 0x1017;
            }
            else
            {
                cmd = 0x1016;
            }

            ///Pack
            Packs(len, cmd, val);
        }

        public void CboFlip_SelectedIndexChanged(object sender, EventArgs e)
        {
            ///Declaration
            int num = cboFlip.SelectedIndex;
            len = 0x0000;

            ///Code
            if (num == 0)
            {
                cmd = 0x1050;
            }
            else if (num == 1)
            {
                cmd = 0x1051;
            }
            else if (num == 2)
            {
                cmd = 0x1052;
            }
            else
            {
                cmd = 0x1053;
            }

            ///Pack
            Packs(len, cmd, val);
        }

        public void chkboxDDE_CheckedChanged(object sender, EventArgs e)
        {
            ///Declaration
            byte lit_val, lar_val;
            cmd = 0x1019;
            len = 0x0001;

            ///Code
            if (chkboxDDE.Checked)
            {
                lit_val = (byte)trkbarFine.Value;
                lar_val = (byte)trkbarCoarse.Value;
                val = (byte)((lar_val << 4) + lit_val);
            }
            else
            {
                cmd = 0x1018;
                len = 0x0000;
            }

            ///Pack
            Packs(len, cmd, val);
        }

        public void TrkbarFine_Scroll(object sender, EventArgs e)
        {
            ///Declaration
            byte lit_val, lar_val;
            cmd = 0x1019;
            len = 0x0001;

            ///Code
            if (chkboxDDE.Checked)
            {
                lit_val = (byte)trkbarFine.Value;
                lar_val = (byte)trkbarCoarse.Value;
                val = (byte)((lar_val << 4) + lit_val);
            }

            else
            {
                return;
            }

            ///Pack
            Packs(len, cmd, val);
        }

        public void TrkbarCoarse_Scroll(object sender, EventArgs e)
        {
            ///Declaration
            byte lit_val, lar_val;
            cmd = 0x1019;
            len = 0x0001;

            ///Code
            if (chkboxDDE.Checked)
            {
                lit_val = (byte)trkbarFine.Value;
                lar_val = (byte)trkbarCoarse.Value;
                val = (byte)((lar_val << 4) + lit_val);
            }
            else
            {
                return;
            }

            ///Pack
            Packs(len, cmd, val);
        }

        public void chkboxMan_CheckedChanged(object sender, EventArgs e)
        {
            ///Declaration
            uint gain, offset;
            cmd = 0x1020;
            len = 0x0004;

            if (chkboxMan.Checked)
            {
                gain = (uint)trkbarCon.Value;
                offset = (uint)trkbarBright.Value;
                val = (gain << 16) + offset;
            }
            else
            {
                cmd = 0x1021;
                len = 0x0000;
            }

            ///Pack
            Packs(len, cmd, val);
        }

        public void TrkbarCon_Scroll(object sender, EventArgs e)
        {
            ///Declaration
            uint gain, offset;
            cmd = 0x1020;
            len = 0x0004;

            ///Code
            if (chkboxMan.Checked)
            {
                gain = (uint)trkbarCon.Value;
                offset = (uint)trkbarBright.Value;
                val = (gain << 16) + offset;
            }
            else
            {
                return;
            }

            ///Pack
            Packs(len, cmd, val);
        }

        public void TrkbarBright_Scroll(object sender, EventArgs e)
        {
            ///Declaration
            uint gain, offset;
            len = 0x0004;
            cmd = 0x1020;

            ///Code
            if (chkboxMan.Checked)
            {
                gain = (uint)trkbarCon.Value;
                offset = (uint)trkbarBright.Value;
                val = (gain << 16) + offset;
            }
            else
            {
                return;
            }

            ///Pack
            Packs(len, cmd, val);
        }

        public void chkboxCursor_CheckedChanged(object sender, EventArgs e)
        {
            ///Declaration
            len = 0x0001;
            cmd = 0x1034;

            ///Code
            if (chkboxCursor.Checked)
            {
                val = 0x01;
            }
            else
            {
                val = 0x00;
            }

            ///Pack
            Packs(len, cmd, val);
        }

        public void SendPosition(int Ypos, int Xpos)
        {
            ///Declaration
            cmd = 0x1035;
            len = 0x0004;

            ///Code
            val = (uint)((Ypos << 16) + Xpos);

            ///Pack
            Packs(len, cmd, val);
        }

        public void btnTt_Click(object sender, EventArgs e)
        {
            int y;

            y = int.Parse(txtboxY.Text);

            if ((y - 16) < 0)
            {
                return;
            }
            else
            {
                y -= 16;
                txtboxY.Text = y.ToString();
            }

            int x = int.Parse(txtboxX.Text);
            SendPosition(y, x);
        }

        public void BtnT_Click(object sender, EventArgs e)
        {
            int y;

            y = int.Parse(txtboxY.Text);

            if (y <= 0)
            {
                return;
            }
            else
            {
                y--;
                txtboxY.Text = y.ToString();
            }

            int x = int.Parse(txtboxX.Text);
            SendPosition(y, x);
        }

        public void BtnD_Click(object sender, EventArgs e)
        {
            int y;

            y = int.Parse(txtboxY.Text);

            if (y >= (height - 1))
            {
                return;
            }
            else
            {
                y++;
                txtboxY.Text = y.ToString();
            }

            int x = int.Parse(txtboxX.Text);
            SendPosition(y, x);
        }

        public void BtnDd_Click(object sender, EventArgs e)
        {
            int y;

            y = int.Parse(txtboxY.Text);

            if ((y + 16) > (height - 1))
            {
                return;
            }
            else
            {
                y += 16;
                txtboxY.Text = y.ToString();
            }

            int x = int.Parse(txtboxX.Text);
            SendPosition(y, x);
        }

        public void BtnL_Click(object sender, EventArgs e)
        {
            int x;

            x = int.Parse(txtboxX.Text);

            if (x <= 0)
            {
                return;
            }
            else
            {
                x--;
                txtboxX.Text = x.ToString();
            }

            int y = int.Parse(txtboxY.Text);
            SendPosition(y, x);
        }

        public void BtnLl_Click(object sender, EventArgs e)
        {
            int x;

            x = int.Parse(txtboxX.Text);

            if ((x - 16) < 0)
            {
                return;
            }
            else
            {
                x -= 16;
                txtboxX.Text = x.ToString();
            }

            int y = int.Parse(txtboxY.Text);
            SendPosition(y, x);
        }

        public void BtnR_Click(object sender, EventArgs e)
        {
            int x;

            x = int.Parse(txtboxX.Text);

            if (x >= (width - 1))
            {
                return;
            }
            else
            {
                x++;
                txtboxX.Text = x.ToString();
            }

            int y = int.Parse(txtboxY.Text);
            SendPosition(y, x);
        }

        public void BtnRr_Click(object sender, EventArgs e)
        {
            int x;

            x = int.Parse(txtboxX.Text);

            if ((x + 16) > (width - 1))
            {
                return;
            }
            else
            {
                x += 16;
                txtboxX.Text = x.ToString();
            }

            int y = int.Parse(txtboxY.Text);
            SendPosition(y, x);
        }

        public void BtnMid_Click(object sender, EventArgs e)
        {
            txtboxX.Text = (width / 2).ToString();
            txtboxY.Text = (height / 2).ToString();

            int x = int.Parse(txtboxX.Text);
            int y = int.Parse(txtboxY.Text);
            SendPosition(y, x);
        }
    }
}

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

access a Form1 public function from static class inside Form1


Tag : chash , By : TheMoo
Date : March 29 2020, 07:55 AM
With these it helps The point of static code is that belongs to itself, rather than any other object. For this to be true, when you set something as static, everything that depends on it must also be static!
This is what your error message is trying to tell you. You are declaring something as static, but in the computation of that static, you are using something that is not static. Str2Int is not tagged as static, so that is an immediate problem, and it's possible that LoadedRef is also not static. I am half-sure you actually meant to use LoadedRefrnce there, in which case you're fine, but since you spelled nothing correctly I can't be sure!

how would I show the original Form2 from inside Form1 when I press button on Form1 in C#


Tag : chash , By : dlouzan
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further In addition to storing a reference to your Form at Class level, you need to check if it has been closed since the last time it was used. In that case you'd need to create a new instance (just as you do for the very first use). The below example also restores the form if it was minimized:
public partial class Form1 : Form
{

    Form2 F2 = null;

    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        if (F2 == null || F2.IsDisposed)
        {
            F2 = new Form2();
            F2.Show();
        }
        else
        {
            if (F2.WindowState == FormWindowState.Minimized)
            {
                F2.WindowState = FormWindowState.Normal;
            }
            F2.Activate();
        }
    }

}

in c#, I want to send Form1's string's value to appear in Form2's textBox when I click a button of Form1


Tag : chash , By : user133834
Date : March 29 2020, 07:55 AM
it helps some times I would recommend having a data model layer in your application. The data model would have properties that can be accessed by either Form and would send out events when those properties are changed. When a value is chosen on Form1, it sets the corresponding property on the data model, which then fires an event. Form2 handles that event and is then able to retrieve the new value from the data model. This way, neither form needs to know about the other but the data is still shared.
Hopefully that gets you started. There are plenty of resources available online on how to build an application with a model-view pattern (common implementations are model-view-controller or model-view-viewmodel) and explaining them is beyond the scope of this answer.

How can i call a method from form1 to a new class without making the method in form1 static?


Tag : chash , By : Skee
Date : March 29 2020, 07:55 AM
will help you You are storing the parameter from the constructor as it's base type Form instead of it's actual type Form1.
Change
private static Form frm1 = null;
private static Form1 frm1 = null;

How can i call a method with parameter of form1 from form2 and plot on chart on form1


Tag : chash , By : Matthew Steed
Date : March 29 2020, 07:55 AM
this one helps. First of all, you should refactor your code and separate that graph plotting method in it's separate class and then you shouldn't face this situation.
In your case, you can have a Form1 instance in your Form2 and using that instance call the method like
Public class Form2 : Form
{
  public Form1 frm1 = null;
  public Form2(Form1 frm)
  {
    this.frm1 = frm;
  }

 protected void btn_click(object sender, EventArgs e)
{
  frm1.Plottingmethod();
}
} 
Related Posts Related QUESTIONS :
  • Pool of objects with objects that are already on the scene in advance
  • StatusBar text fade-out when binding using Caliburn.Micro
  • Queryfilter on ApplicationUser in OnModelCreating in ApplicationDbContext creates StackOverflowException
  • How to get record form a different table based on a value from first table with linq expression?
  • Show data in Grid from returned model
  • Using Attributes to Override Data Model Conventions
  • Basic OOP console calculator, result Error
  • Compositon and Repository pattern
  • Multiple using statements with if condition
  • How do i increase a number by 1 in every line that contain the number 1
  • Add binding to elements that are created in codebehind
  • How to add a column in an existing AspNetUsers table
  • Order a list of elements with another list of doubles
  • How to setup a NuGet package to copy content files to output build directory?
  • In SignalR Core using ChannelWriter: Do I need to call TryComplete twice if there's an exception?
  • C# GetProcessesByName: issue with colon
  • c# wpf | create complex object with user-defined name to Serialize into JSON
  • How can I get a instance of a generic list with reflection?
  • WPF XAML - Design time and visibility of textbox
  • EF Core and MySql query is too slow
  • Getting Registered App Display Name from an App Id
  • How to get all variables from a string
  • Delete entity with all childs connected
  • Azure Build agent cant´t find class library referance
  • Initialize Nested Dictionaries in c#
  • .Net Core Binding
  • Generic event test method, preventing code duplication
  • How do I keep the ellipses in the center when the screen is resized
  • How to require a property using JsonSchema.NET?
  • C# XDocument Element/Elements returns null
  • Autofac keyed service with IEnumerable relationship type
  • Installing EntityFramework via NuGet manager
  • Always Check if there is Internet Connection Xamarin forms
  • WCF OneWay service slows down when aspNetCompatibilityEnabled is set to false
  • Can we use JsonRequestBehavior.AllowGet with [HttpPost] attribute?
  • How to customize the Setup wizard with custom forms in Visual Studio setup project
  • C# ASP.NET - Use method from another class to create labels
  • C# List IList or IEnumerable as argument
  • Parsing File with C# And Replace method
  • Losing special unicode characters in encryption (C#)
  • Getting stored procedure returned value instead of row affected
  • How can I construct HTML using NameValuePair in android?
  • Loading a pop up page in ASP.net through a js file
  • How to pass alert or notification message from controller to View?
  • C# to pause, turn on ssas server, backup cube.... how to?
  • How to execute DataTable.Select() for a column of custom class type for a particular element in that C#
  • how to connect mysql8.0 with C#
  • Passing incorrect values into MultiValueConverter by MultiBinding
  • Can i use IEnumerator as Update func?
  • How to convert API Json response to C# Array?
  • Blazor Textfield Oninput User Typing Delay
  • Performing both layout and render transform results in wrong output
  • uwp beforetextchanged cursor moving in front of text
  • How to keep duplicates from a string[] exclude words from a List and print them out
  • .Net Core Strings.Asc/Mid/Chr/Len missing even after importing Microsoft.VisualBasic
  • How to return to previous search page without being asked to Confirm Form Re-submission and keeping the results on ASP.N
  • How set a identity scaffolding item/page how initial page in asp.net MVC core?
  • LINQ isn't calling Dispose on my IEnumerator when using Union and Select, expected behavior or bug?
  • What is "ByteArray.uncompress()" in AS3 equivalent to in C#?
  • Getting a specific letter from a string variable for my simple guessing game for clues
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com