Post: Tab Control
05-25-2016, 03:22 PM #1
(adsbygoogle = window.adsbygoogle || []).push({}); si i made a custom tab control but it was a lot of code, can someone thats really good in c# try to minimize the code plaease

Download: You must login or register to view this content.

Virus Scan: Not Needed, it's Open Source
05-28-2016, 04:57 AM #2
Toxic
former staff
Originally posted by VadRe View Post
si i made a custom tab control but it was a lot of code, can someone thats really good in c# try to minimize the code plaease

Download: You must login or register to view this content.

Virus Scan: Not Needed, it's Open Source


What do you mean by 'minimize' the code? You mean make it shorter? You wont get the same result if i do :|
Also, put a virus scan since you got a .exe in the folder (bin > debug > WindowsFormsApplication10.exe)
05-28-2016, 04:37 PM #3
Originally posted by Toxic View Post
What do you mean by 'minimize' the code? You mean make it shorter? You wont get the same result if i do :|
Also, put a virus scan since you got a .exe in the folder (bin > debug > WindowsFormsApplication10.exe)


ok, if its not possible to minimize the code then you can remove the thread
05-28-2016, 04:45 PM #4
Default Avatar
Oneup
Guest
Originally posted by VadRe View Post
ok, if its not possible to minimize the code then you can remove the thread


You can shrink the code down a bit. You can write a function or 2 to essentially do all of this.

Pass the picture box as an object to the function and do your conditionals in that.
05-28-2016, 05:38 PM #5
Originally posted by 1UP View Post
You can shrink the code down a bit. You can write a function or 2 to essentially do all of this.

Pass the picture box as an object to the function and do your conditionals in that.


im not good enough in c# to understand that
05-28-2016, 06:57 PM #6
Default Avatar
Oneup
Guest
Originally posted by VadRe View Post
im not good enough in c# to understand that


I managed to get it down to a few functions. I suggest not using picture boxes with labels on top of them because it just adds to the complexity. I would just change those to buttons.
    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 WindowsFormsApplication10
{
public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();
}

private void toggleTabs(object sender,EventArgs e)
{
PictureBox pctClicked = (PictureBox)sender; //Get the object that called this function
string[] senderPosition = pctClicked.Name.Split('_'Winky Winky; //We want to know what the number is. On the control's name I put an underscore and a number to represent it's position
tabControl1.SelectedIndex = Int32.Parse(senderPosition[1]) - 1; //The tab control has a selected index property so we can tell it what tab to goto with that

}

private void mousein(object sender, EventArgs e)
{
PictureBox pct_mousedIn = (PictureBox)sender;
pct_mousedIn.BackColor = Color.Green;

}

private void mouseOut(object sender, EventArgs e)
{
PictureBox pct_mouseOut = (PictureBox)sender;
pct_mouseOut.BackColor = Color.LimeGreen;

}
}



}



Here is the new source:
You must login or register to view this content.

There are probably even better ways to do this but I think 20ish lines or whatever it came out to be is alot better than 1200.
This isn't fully functional and you may still need to make changes / finish the code.
Last edited by Oneup ; 05-28-2016 at 07:00 PM.

The following user thanked Oneup for this useful post:

NMT_VadRe
05-28-2016, 07:26 PM #7
Originally posted by 1UP View Post
I managed to get it down to a few functions. I suggest not using picture boxes with labels on top of them because it just adds to the complexity. I would just change those to buttons.
    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 WindowsFormsApplication10
{
public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();
}

private void toggleTabs(object sender,EventArgs e)
{
PictureBox pctClicked = (PictureBox)sender; //Get the object that called this function
string[] senderPosition = pctClicked.Name.Split('_'Winky Winky; //We want to know what the number is. On the control's name I put an underscore and a number to represent it's position
tabControl1.SelectedIndex = Int32.Parse(senderPosition[1]) - 1; //The tab control has a selected index property so we can tell it what tab to goto with that

}

private void mousein(object sender, EventArgs e)
{
PictureBox pct_mousedIn = (PictureBox)sender;
pct_mousedIn.BackColor = Color.Green;

}

private void mouseOut(object sender, EventArgs e)
{
PictureBox pct_mouseOut = (PictureBox)sender;
pct_mouseOut.BackColor = Color.LimeGreen;

}
}



}



Here is the new source:
You must login or register to view this content.

There are probably even better ways to do this but I think 20ish lines or whatever it came out to be is alot better than 1200.
This isn't fully functional and you may still need to make changes / finish the code.


thank you

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo