• ** There has been a recent site upgrade. Please clear your browser cache to avoid issues. **
  • New forum feature - post voting and best solution

    Check out this thread for the details: https://www.access-programmers.co.uk/forums/threads/new-forum-feature-post-voting-and-best-answer.314134/

    This new feature looks great to me! :)

  • We now have 3 forum themes

    Go for the default (light) theme, Shades of Grey or Shades of Blue. I just added the Blue one.

    The thread about it is here: https://www.access-programmers.co.uk/forums/threads/new-forum-theme-shades-of-blue.314136/

Add Multi GroupBox and show messgebox (GB.text) for every groupbox but Always messgebox last groupbox (1 Viewer)

ee406621

New member
Local time
Today, 12:25
Joined
Feb 23, 2019
Messages
9
GroupBox GB ;

int num = 0;


for (int i = 1; i < 5; i++)
{
num += 1;

GB = new GroupBox();
GB.Name ="GB" + i;
GB.Text = "GB" + i;
GB.Size= new Size( 964, 40);

GB.Click += new EventHandler(test);

int LocationX = Convert.ToInt32(GB.Location.X);
Locationy = Locationy + 120;
GB.Location = new Point(LocationX, Locationy);

this.Controls.Add(GB);
}



protected void test(object sender, EventArgs e)
{
MessageBox.Show(GB.Text);
}
 
Last edited:

Isaac

Lifelong Learner
Local time
Today, 02:25
Joined
Mar 14, 2017
Messages
2,330
Code:
Public Class VDMmsgbox
    ' Display a custom - big msgbox instead of the standard one
    Private MBrslt As Integer = 0
    Private BTNnum As Integer = 0 ' number of buttons to display
    private BTNtxt(10) As String
    Public Function BigMsgBox(ByVal Prompt As Object, Optional ByVal BigButtons As BigMsgBoxButtons = BigMsgBoxButtons.OKOnly, Optional ByVal Title As Object = Nothing, Optional ByVal Colorr As Color = Nothing) As MsgBoxResult

        Select Case BigButtons
            Case BigMsgBoxButtons.OKOnly
                BTNnum = 1
                BTNtxt(1) = "OK"
            Case BigMsgBoxButtons.OKCancel
                BTNnum = 2
                BTNtxt(1) = "OK"
                BTNtxt(2) = "CANCEL"
            Case BigMsgBoxButtons.AbortRetryIgnore
                BTNnum = 3
                BTNtxt(1) = "ABORT"
                BTNtxt(2) = "RETRY"
                BTNtxt(3) = "IGNORE"
            Case BigMsgBoxButtons.YesNoCancel
                BTNnum = 3
                BTNtxt(1) = "YES"
                BTNtxt(2) = "NO"
                BTNtxt(3) = "CANCEL"
            Case BigMsgBoxButtons.YesNo
                BTNnum = 2
                BTNtxt(1) = "YES"
                BTNtxt(2) = "NO"
            Case BigMsgBoxButtons.RetryCancel
                BTNnum = 2
                BTNtxt(1) = "RETRY"
                BTNtxt(2) = "CANCEL"
        End Select


        ' Lets build the lables:

        Me.Width = 417
        Me.Height = 340

        Dim TitleTrue As Boolean = False
        If Title IsNot Nothing Then
            Dim LBL_Title As New Label
            LBL_Title.Name = "LBL_Title"
            LBL_Title.Width = Me.Width - 2
            LBL_Title.Left = 1
            LBL_Title.Height = 60
            LBL_Title.TextAlign = ContentAlignment.MiddleCenter
            LBL_Title.Text = Title.ToString
            Controls.Add(LBL_Title)
            TitleTrue = True
        End If
        If Prompt IsNot Nothing Then
            Dim lbl_msg As New Label
            lbl_msg.Name = "LBL_Msg"
            lbl_msg.Left = 6
            lbl_msg.Width = Me.Width - 12
            If TitleTrue = True Then
                lbl_msg.Top = 70
            Else
                lbl_msg.Top = 10
            End If
            lbl_msg.Height = Me.Height - 250
                lbl_msg.TextAlign = ContentAlignment.TopLeft
                lbl_msg.Text = Prompt.ToString
                Controls.Add(lbl_msg)
            End If

            ' -------------------------------       Lets build the buttons:
            Dim Location_control As New Point(0, Me.Height - 100)
        Dim new_Button(BTNnum) As Button
        'Dim BTNwidth = ((Me.Width - 20) - (BTNnum * 5)) / BTNnum
        Dim BTNwidth = Me.Width / BTNnum - 2
        For Count_control = 1 To BTNnum

            'SET A NEW BUTTON
            new_Button(Count_control) = New Button
            new_Button(Count_control).Name = "BTN" & Count_control
            new_Button(Count_control).Text = BTNtxt(Count_control) '"Button" + Count_control.ToString()
            new_Button(Count_control).Location = New Point((BTNwidth * (Count_control - 1)), Location_control.Y)
            new_Button(Count_control).Width = (BTNwidth)
            new_Button(Count_control).Height = 90
            AddHandler new_Button(Count_control).Click, AddressOf myButtonHandler_Click
            Controls.Add(new_Button(Count_control))
        Next

        Try
            Me.ShowDialog()
        Catch ex As Exception

        End Try

        Return MBrslt
        Me.Close()
    End Function

    Private Sub myButtonHandler_Click(ByVal sender As Object, ByVal e As EventArgs)
        If TypeOf sender Is Button Then
            Select Case sender.text.ToString

                Case "OK"
                    MBrslt = 1
                Case "CANCEL"
                    MBrslt = 2
                Case "ABORT"
                    MBrslt = 3
                Case "RETRY"
                    MBrslt = 4
                Case "IGNORE"
                    MBrslt = 5
                Case "YES"
                    MBrslt = 6
                Case "NO"
                    MBrslt = 7
            End Select
        End If

        Me.Visible = False
        Controls.Clear()
        Me.Close()
    End Sub


End Class
 

arnelgp

error reading drive A:
Local time
Today, 17:25
Joined
May 7, 2009
Messages
10,525
how do you translate that in C?
 

ee406621

New member
Local time
Today, 12:25
Joined
Feb 23, 2019
Messages
9
Resoved 👍 C#


C#:
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;



namespace WindowsFormsApp1

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

            Shown += Form1_Shown;

            Locationy = 1;

        }



        private void Form1_Shown(object sender, EventArgs e)

        {

            GroupBox GB;

            int num = 0;

            for (int i = 1; i < 5; i++)

            {

                num += 1;



                GB = new GroupBox();

                GB.Name = "GB" + i;

                GB.Text = "GB" + i;

                GB.Size = new Size(964, 40);

                GB.Click += new EventHandler(test);

                int LocationX = Convert.ToInt32(GB.Location.X);

                Locationy = Locationy + 120;

                GB.Location = new Point(LocationX, Locationy);

                this.Controls.Add(GB);

            }

        }



        public int Locationy { get; set; }



        protected void test(object sender, EventArgs e)

        {

            MessageBox.Show(((GroupBox) sender).Text);

        }

    }

}
 

Users who are viewing this thread

Top Bottom