using System.Collections.Generic;
namespace MainForm.Core {
public class Map<T, V> : Dictionary<T, V> {
public void put(T t, V v) {
if (this.Keys == null || this.Keys.Count < 1 || !this.ContainsKey(t)) {
Add(t, v);
} else {
this[t] = v;
}
}
}
}
//---------------------------------------------------------------------------------------
using System;
using MainForm;
public class Variables {
//bu yerda TabControlning TabPanel ida belgi(name, title) qo`yilmaydi
public const string NO_WRITE = "Rahimjon";
}
//---------------------------------------------------------------------------------------
using System.Windows.Forms;
namespace MainForm.Core {
public class Panel : System.Windows.Forms.Panel {
HorizontalPanel p = null;
public Panel() {
//p.Height = 10;
p = new HorizontalPanel(true);
p.Dock = DockStyle.Bottom;
p.BackColor = System.Drawing.Color.Transparent;
p.Name = Variables.NO_WRITE;
p.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(p);
p.AutoScroll = false;
}
Map<string, string> dict = new Map<string, string>();
public void add(Control value, string text) {
dict.put(value.Name, text);
if (Controls.IndexOfKey(value.Name) > -1) {
BringToFront(value.Name);
} else {
Controls.Add(value);
value.Dock = DockStyle.Fill;
}
}
public void addNew(Control value, string text) {
dict.put(value.Name, text);
Controls.RemoveByKey(value.Name);
Controls.Add(value);
value.Dock = DockStyle.Fill;
}
public void BringToFront(string name) {
if (!Controls.ContainsKey(name)) { return; }
Controls[Controls.IndexOfKey(name)].BringToFront();
selected(name);
}
protected override void OnControlAdded(ControlEventArgs e) {
if ("".Equals(e.Control.Name)) { Controls.Remove(e.Control); return; }
if (Controls.Find(e.Control.Name, true).Length > 1) {
Controls.Remove(e.Control);
BringToFront(e.Control.Name);
}
BringToFront(e.Control.Name);
getPage(e.Control);
}
Button getPage(Control c) {
if (Variables.NO_WRITE.Equals(c.Name)) { return null; }
Button b = new Button();
b.Text = dict[c.Name];
b.Name = c.Name;
b.AutoSize = true;
p.add(b);
b.Click += new System.EventHandler(pageClick);
selected(c.Name);
return b;
}
void selected(string name) {
if (Variables.NO_WRITE.Equals(name)) { return; }
foreach (Control s in p.Controls) {
if (s.GetType() == typeof(Button)) {
((Button)s).FlatStyle = FlatStyle.Standard;
}
}
if (p.Controls.ContainsKey(name) && typeof(Button) == p.Controls[name].GetType()) {
((Button)p.Controls[name]).FlatStyle = FlatStyle.Flat;
}
}
void pageClick(object sender, System.EventArgs e) {
BringToFront(((Button)sender).Name);
}
public void clear() {
Controls.Clear();
}
protected override void OnControlRemoved(ControlEventArgs e) {
if (!Variables.NO_WRITE.Equals(e.Control.Name)) {
p.Controls.RemoveByKey(e.Control.Name);
}
}
public void RemoveByKey(string name) {
if (!(Utils.isNullOrEmpty(name) || Variables.NO_WRITE.Equals(name))) {
p.Controls.RemoveByKey(name);
}
}
public void Remove(Control control) {
if (control != null) {
RemoveByKey(control.Name);
}
}
}
}