Пример #1
0
        public Assignment_Dlg(Rectangle parent_Rec, Visual_Flow_Form form)
        {
            int index;

            Rec      = parent_Rec;
            the_form = form;
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            Dialog_Helpers.Init();
            this.label1.Text = "Enter an assignment." +
                               '\n' + '\n' + "Examples:" + '\n' + "   Set Coins to 5" +
                               '\n' + "   Set Count to Count + 1" +
                               '\n' + "   Set Board[3,3] to 0";
            this.labelGraphics = label2.CreateGraphics();
            if (Rec.Text != null)
            {
                index = Rec.Text.IndexOf(":=");
                if (index > 0)
                {
                    this.lhsTextBox.Text      = Rec.Text.Substring(0, index);
                    this.assignment_Text.Text =
                        Rec.Text.Substring(index + 2,
                                           Rec.Text.Length - (index + 2));
                }
                else
                {
                    this.lhsTextBox.Text = Rec.Text;
                }
            }
        }
Пример #2
0
        public double[] CharToDoubleArray(char aChar, Font aFont, int aArrayDim, int aAddNoisePercent)
        {
            double[] result = new double[aArrayDim * aArrayDim];
            Graphics gr     = label5.CreateGraphics();
            Size     size   = Size.Round(gr.MeasureString(aChar.ToString(), aFont));
            Bitmap   aSrc   = new Bitmap(size.Width, size.Height);
            Graphics bmp    = Graphics.FromImage(aSrc);

            bmp.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.None;
            bmp.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
            bmp.Clear(Color.White);
            bmp.DrawString(aChar.ToString(), aFont, new SolidBrush(Color.Black), new Point(0, 0), new StringFormat());
            ShowNoise(size, bmp, aAddNoisePercent);
            pictureBox1.Image = aSrc;
            Application.DoEvents();
            double xStep = (double)aSrc.Width / (double)aArrayDim;
            double yStep = (double)aSrc.Height / (double)aArrayDim;

            for (int i = 0; i < aSrc.Width; i++)
            {
                for (int j = 0; j < aSrc.Height; j++)
                {
                    int   x = (int)((i / xStep));
                    int   y = (int)(j / yStep);
                    Color c = aSrc.GetPixel(i, j);
                    result[y * x + y] += Math.Sqrt(c.R * c.R + c.B * c.B + c.G * c.G);     //Convert to BW, I guess I can use B component of Alpha color space too...
                }
            }
            return(Scale(result));
        }
Пример #3
0
        private void CenterFG()
        {
            float ΔWidth = gLabel.CreateGraphics().
                           MeasureString(gLabel.Text, gLabel.Font).Width -
                           fLabel.CreateGraphics().
                           MeasureString(fLabel.Text, fLabel.Font).Width;
            int spacing = gLabel.Location.X - (fLabel.Location.X + fLabel.Size.Width);

            Trace.Assert(spacing == 0);
            if (HasG)
            {
                // Adjust the widths so as to center the text.
                fLabel.Size = new Size
                                  ((int)(((float)fgWidth - ΔWidth - (float)spacing) / 2.0),
                                  fLabel.Size.Height);
                gLabel.Size = new Size
                                  (fgWidth - fLabel.Size.Width - spacing,
                                  gLabel.Size.Height);
                gLabel.Location = new Point
                                      (fLabel.Location.X + fgWidth - gLabel.Size.Width,
                                      gLabel.Location.Y);

                // Now set the alignments.
                fLabel.TextAlign = ContentAlignment.TopRight;
                gLabel.TextAlign = ContentAlignment.TopLeft;
            }
            else
            {
                fLabel.TextAlign = ContentAlignment.TopCenter;
            }
        }
Пример #4
0
        //private Point m_pLocation;

        internal CHelpDialog(String sHelp, Point pPosition)
        {
            InitializeComponent();
            m_lbl.Text = sHelp;

            // Let's figure out how big to make the label....
            SizeF sf = m_lbl.CreateGraphics().MeasureString(sHelp, m_lbl.Font, new SizeF(400, 0));

            sf         = new SizeF(sf.Width + 1, sf.Height + 1);
            m_lbl.Size = sf.ToSize();

            // We want to pop up just below this control
            pPosition.Y += 10;

            // Make sure we won't go off the top of the screen

            if (pPosition.X < 0)
            {
                pPosition.X = 1;
            }
            if (pPosition.Y < 0)
            {
                pPosition.Y = 1;
            }

            // We should probably also make sure we don't fly off the bottom or the
            // right, but we need some text sizes to be able to make that call.

            Location = pPosition;
        }// CHelpDialog
Пример #5
0
        public PopupWindow(Control parent, string caption, Point location, bool mayBeToLeft)
        {
            m_message = caption;

            InitializeComponent();

            SizeF sizef       = messageLabel.CreateGraphics().MeasureString(m_message, messageLabel.Font);
            int   labelWidth  = (int)(sizef.Width * 1.05f);             // need just a little bit to make sure it stays single line
            int   labelHeight = (int)(sizef.Height);

            Rectangle bounds = new Rectangle(location.X + SHIFT_HORIZ, location.Y - SHIFT_VERT, labelWidth, labelHeight);

            if (mayBeToLeft && parent != null)
            {
                try
                {
                    Rectangle parentBounds = new Rectangle(parent.PointToScreen(new Point(0, 0)), parent.Size);
                    //m_message = "" + parentBounds;
                    if (!parentBounds.Contains(bounds))
                    {
                        bounds = new Rectangle(location.X - labelWidth - SHIFT_HORIZ, location.Y - SHIFT_VERT, labelWidth, labelHeight);
                    }
                }
                catch {}
            }
            this.Bounds = bounds;

            messageLabel.Text = m_message;
            this.Focus();               // this normally won't work as Project.ShowPopup tries to return focus to parent. Hover mouse to regain focus
        }
		public void Init()
		{
			Label l = new Label();
			this.graphics = l.CreateGraphics();
			section = new BaseSection();
			section.Location = new Point (50,50);
			section.Size = new Size(400,200);
		}
        private void AjustarTamanhoFonte(Label label)
        {
            Graphics graphics = label.CreateGraphics();
            SizeF textSize = graphics.MeasureString(label.Text, label.Font);

            float falta = textSize.Width + 100 - label.Width;
            if (falta > 0)
                label.Font = new Font(label.Font.FontFamily, label.Font.Size - Math.Abs(falta) / 200, FontStyle.Bold);
        }
Пример #8
0
 private void adjustLabelSize(Label label)
 {
     string text = label.Text;
     Graphics g = label.CreateGraphics();
     SizeF oSize = g.MeasureString(text, label.Font);
     int nWidth = (int)oSize.Width + 5;
     int nHeight = 20;
     label.Width = nWidth;
     label.Height = nHeight;
 }
Пример #9
0
        public static void InitBorderTitle(this Control ctrl, Window window, Control child)
        {
            if (window is ActiveWindow)
            {
                ActiveWindow wnd = (ActiveWindow)window;
                if (ctrl.Controls.ContainsKey("LabelTitle")) ctrl.Controls.RemoveByKey("LabelTitle");
                if (wnd.BorderVisible)
                {
                    ctrl.SuspendLayout();
                    child.SuspendLayout();
                    child.Left += wnd.BorderWidth;
                    child.Width -= wnd.BorderWidth << 1;
                    child.Height -= wnd.BorderWidth;

                    System.Windows.Forms.Label title = new System.Windows.Forms.Label();
                    title.AutoSize = false;
                    title.Name = "LabelTitle";
                    title.BackColor = wnd.BorderColorFrienly;
                    title.Font = new Font(wnd.TitleFont, wnd.TitleSize);
                    title.ForeColor = wnd.TitleColorFrienly;
                    title.Text = wnd.TitleText;
                    title.Left = wnd.BorderWidth;
                    title.Top = 0;
                    using (Graphics g = title.CreateGraphics())
                    {
                        title.Size = g.MeasureString(wnd.TitleText, title.Font).ToSize();
                    }
                    title.Width = child.Width;
                    title.AutoEllipsis = true;
                    title.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;

                    ctrl.Controls.Add(title);
                    if (title.Height == 0)
                    {
                        child.Top += wnd.BorderWidth;
                        child.Height -= wnd.BorderWidth;
                    }
                    else
                    {
                        child.Top += title.Height;
                        child.Height -= title.Height;
                    }

                    ctrl.BackColor = wnd.BorderColorFrienly;
                    child.ResumeLayout();
                    ctrl.ResumeLayout();
                    title.Invalidate();
                }
                ctrl.Text = wnd.TitleText;
            }
        }
Пример #10
0
        private void InvoiceControl_Load( object sender, EventArgs e )
        {
            if( invoice == null ) {
                return;
            }
            lblName.Text = string.Format( "{0}, {1}, {2} kr", invoice.Name, invoice.Date.ToString( "yyyy-MM-dd" ), invoice.Amount );
            int y = 0;
            if( !string.IsNullOrEmpty( invoice.Comment ) ) {
                using( Font font = new Font( "Microsoft Sans Serif", 8, FontStyle.Italic ) ) {
                    Label l = new Label { Text = invoice.Comment, Top = y, Left = 10, Font = font, AutoSize = true, Width = pnlPayments.Width - 5, Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right };
                    using( Graphics gr = l.CreateGraphics() ) {
                        SizeF measureString = gr.MeasureString( invoice.Comment, font );
                        l.Height = (int)(measureString.Height + 5);
                    }
                    pnlPayments.Controls.Add( l );
                    y += l.Height + 5;
                }
            }
            using( Font font = new Font( "Microsoft Sans Serif", 9 ) ) {
                Label l;
                foreach( InvoicePayment payment in invoice.Payments ) {
                    l = new Label { Text = string.Format( "{0} kr", payment.Amount ), Top = y, Left = 10, Font = font, AutoSize = true};
                    pnlPayments.Controls.Add( l );
                    l = new Label { Text = string.Format( "{0}", payment.Date.ToString( "yyyy-MM-dd" ) ), Top = y, Left = 100, Font = font, AutoSize = true };
                    pnlPayments.Controls.Add( l );
                    y += l.Height + 5;
                }
                if( y == 0 ) {
                    l = new Label { Text = "No payments found...", Top = y, Left = 10, Font = font, AutoSize = true };
                    pnlPayments.Controls.Add( l );
                    y += l.Height + 5;
                }
                l = new Label { Text = "Balance", Top = y, Left = 10, Font = font, AutoSize = true };
                l.ForeColor = invoice.Balance <= 0 ? Color.Green : Color.Red;
                pnlPayments.Controls.Add( l );
                l = new Label { Text = string.Format( "{0} kr", invoice.Balance ), Top = y, Left = 100, Font = font, AutoSize = true };
                l.ForeColor = invoice.Balance <= 0 ? Color.Green : Color.Red;
                pnlPayments.Controls.Add( l );
                y += l.Height + 5;

                Button b = new Button { Top = y, Left = 15, Font = font, AutoSize = true, Text = "Add payment" };
                b.Click += AddPaymentClick;
                pnlPayments.Controls.Add( b );
            }
        }
Пример #11
0
        public Call_Dialog(Rectangle parent_Rec, Visual_Flow_Form form)
        {
            Rec      = parent_Rec;
            the_form = form;
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            Dialog_Helpers.Init();

            this.label1.Text = "Enter a procedure call." +
                               '\n' + '\n' + "Examples:" + '\n' + "   Wait_For_Mouse_Button(Left_Button)" +
                               '\n' + "   Open_Graph_Window(300,300)";
            this.labelGraphics = label2.CreateGraphics();
            if (Rec.Text != null)
            {
                this.assignment_Text.Text = Rec.Text;
            }
        }
Пример #12
0
        public Return_Dlg(Oval_Return Parent_Oval, Visual_Flow_Form form)
        {
            RETURN   = Parent_Oval;
            the_form = form;
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            Dialog_Helpers.Init();
            if ((RETURN.Text != null) && (RETURN.Text.CompareTo("") != 0))
            {
                this.textBox1.Text = RETURN.Text;
            }
            this.labelGraphics = label4.CreateGraphics();
            stringFormat       = new System.Drawing.StringFormat();

            // Center the block of text (top to bottom) in the rectangle.
            stringFormat.LineAlignment = System.Drawing.StringAlignment.Center;
        }
Пример #13
0
        public Output_Dlg(Parallelogram Parent_Parallelogram, Visual_Flow_Form form)
        {
            PAR      = Parent_Parallelogram;
            the_form = form;
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            Dialog_Helpers.Init();
            this.label2.Text = "Examples:" + '\n' +
                               "   " + '"' + "exact text" + '"' + '\n' +
                               "   Coins" + '\n' +
                               "   " + '"' + "Number of Coins: " + '"' + "+Coins" + '\n' +
                               "   Board[3,3]";
            this.textBox1.Text    = PAR.Text;
            this.new_line.Checked = PAR.new_line;
            this.labelGraphics    = label4.CreateGraphics();
            stringFormat          = new System.Drawing.StringFormat();

            // Center the block of text (top to bottom) in the rectangle.
            stringFormat.LineAlignment = System.Drawing.StringAlignment.Center;
        }
Пример #14
0
        public Control_Dlg(Component parent_Cmp,
                           Visual_Flow_Form form,
                           bool is_loop)
        {
            Cmp      = parent_Cmp;
            the_form = form;
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            Dialog_Helpers.Init();

            if (is_loop)
            {
                if (!Component.reverse_loop_logic)
                {
                    this.label1.Text = "Enter loop exit condition." +
                                       '\n' + '\n' + this.examples;
                }
                else
                {
                    this.label1.Text = "Enter loop condition." +
                                       '\n' + '\n' + this.examples;
                }
                this.Text = "Enter Loop Condition";
            }
            else
            {
                this.label1.Text = "Enter selection condition." +
                                   '\n' + '\n' + this.examples;
                this.Text = "Enter Selection Condition";
            }
            this.labelGraphics = label2.CreateGraphics();
            if (Cmp.Text != null)
            {
                this.Control_Text.Text = Cmp.Text;
            }
        }
Пример #15
0
        private void DrawLabel(IntPtr handle)
        {
            System.Windows.Forms.Label label = Control.FromHandle(handle) as System.Windows.Forms.Label;
            if (label == null)
            {
                return;
            }

            using (Graphics g = label.CreateGraphics())
            {
                AdvanceDrawing.DrawBlurryTextAndImage(
                    g,
                    label.ClientRectangle,
                    label.Text,
                    label.Font,
                    label.ForeColor,
                    this.BlurColor,
                    label.TextAlign,
                    this.BlurSize,
                    label.Image,
                    label.ImageAlign);
            }
        }
Пример #16
0
        void rptFileReport_ReportStart(object sender, EventArgs e)
        {
            //Căn kích thước của ReportHeader
            foreach (ARControl arControl in this.reportHeader.Controls)
            {
                if (arControl.Tag != null && arControl.Tag.ToString().ToUpper() == "SUBTITLE2")
                {
                    DataDynamics.ActiveReports.Label lblSubTitle2 = (DataDynamics.ActiveReports.Label)arControl;
                    if (lblSubTitle2.Text.Trim() != string.Empty)
                    {
                        System.Windows.Forms.Label lblMeasure = new System.Windows.Forms.Label();
                        lblMeasure.Font = lblSubTitle2.Font;

                        float fHeight;
                        fHeight             = lblMeasure.CreateGraphics().MeasureString(lblSubTitle2.Text, lblMeasure.Font).Height;
                        lblSubTitle2.Height = (float)fHeight / 100 + 0.1F;
                    }
                    //    this.reportHeader.Height = lblSubTitle2.Location.Y + lblSubTitle2.Height;
                    //}
                    //else
                    //    this.reportHeader.Height = lblSubTitle2.Location.Y;
                }
            }

            foreach (ARControl arControl in this.detail.Controls)
            {
                if (arControl.GetType().Name == "Line")
                {
                    Line line = (Line)arControl;
                    line.AnchorBottom = true;
                    if ((line.X1 != line.X2) && (line.Y1 == line.Y2))
                    {
                        dicLineBar[arControl.GetType().Name] = (Line)arControl;
                    }
                }
            }
        }
Пример #17
0
        public Input_Dlg(Parallelogram Parent_Parallelogram, Visual_Flow_Form form)
        {
            PAR      = Parent_Parallelogram;
            the_form = form;
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            Dialog_Helpers.Init();

            if ((PAR.Text != null) && (PAR.Text.CompareTo("") != 0))
            {
                this.exprTextBox.Text     = PAR.prompt;
                this.variableTextBox.Text = PAR.Text;
            }

            this.examplesLabel.Text = "Examples:" + '\n' + "   Coins" +
                                      '\n' + "   Board[3,3]";
            this.labelGraphics = errorLabel.CreateGraphics();
            stringFormat       = new System.Drawing.StringFormat();

            // Center the block of text (top to bottom) in the rectangle.
            stringFormat.LineAlignment = System.Drawing.StringAlignment.Center;
        }
        protected override void OnClick(EventArgs click)
        {
            base.OnClick(click);

            if (this.m_Classrooms.Count <= 0)
                return;

            TCPClassroomManager manager = this.m_Classrooms[0];
            if (!m_Connected) {

                Form form = new Form();
                form.Text = "Connect to TCP Server...";
                form.ClientSize = new Size(350, form.ClientSize.Height);
                form.FormBorderStyle = FormBorderStyle.FixedDialog;

                Label label = new Label();
                label.Text = "Server:";
                using (Graphics graphics = label.CreateGraphics())
                    label.ClientSize = Size.Add(new Size(10, 0),
                        graphics.MeasureString(label.Text, label.Font).ToSize());
                label.Location = new Point(5, 5);

                TextBox host = new TextBox();
                host.Location = new Point(label.Right + 10, label.Top);
                host.Width = form.ClientSize.Width - host.Left - 5;

                Button okay = new Button();
                okay.Text = Strings.OK;
                okay.Width = (host.Right - label.Left) / 2 - 5;
                okay.Location = new Point(label.Left, Math.Max(host.Bottom, label.Bottom) + 10);

                Button cancel = new Button();
                cancel.Text = Strings.Cancel;
                cancel.Width = okay.Width;
                cancel.Location = new Point(okay.Right + 10, okay.Top);

                EventHandler connect = delegate(object source, EventArgs args) {
                    try {
                        //manager.ClientConnect(host.Text); //obsolete
                        this.m_Connected = true;
                        this.Text = "Disconnect from &TCP Server...";
                        form.Dispose();
                    }
                    catch (Exception e) {
                        MessageBox.Show(
                            string.Format("Classroom Presenter 3 was unable to connect to\n\n"
                                + "\t\"{0}\"\n\nfor the following reason:\n\n{1}",
                                host.Text, e.Message),
                            "Connection Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                        this.m_Connected = false;
                    }
                };

                host.KeyPress += delegate(object source, KeyPressEventArgs args) {
                    if (args.KeyChar == '\r')
                        connect(source, EventArgs.Empty);
                };

                okay.Click += connect;

                cancel.Click += delegate(object source, EventArgs args) {
                    this.m_Connected = false;
                    form.Dispose();
                };

                form.ClientSize = new Size(form.ClientSize.Width, Math.Max(okay.Bottom, cancel.Bottom) + 5);

                form.Controls.Add(label);
                form.Controls.Add(host);
                form.Controls.Add(okay);
                form.Controls.Add(cancel);

                DialogResult dr = form.ShowDialog(this.GetMainMenu() != null ? this.GetMainMenu().GetForm() : null);
            }
            else {
                //manager.ClientDisconnect();
                this.Text = "Connect to &TCP Server...";
                m_Connected = false;
            }
        }
Пример #19
0
 private void formatLabelString(Label label, string name)
 {
     Graphics g = label.CreateGraphics();
        try
        {
     SizeF stringSize = g.MeasureString(name, label.Font);
     if (stringSize.Width > label.Width)
     {
      int length = (int)(label.Width * name.Length / stringSize.Width);
      string tmp = String.Empty;
      while (stringSize.Width > label.Width)
      {
       tmp = name.Substring(0, length) + "...";
       stringSize = g.MeasureString(tmp, label.Font);
       length -= 1;
      }
      label.Text = tmp;
      toolTip1.SetToolTip(label, name);
     }
     else
     {
      label.Text = name;
      toolTip1.SetToolTip(label, string.Empty);
     }
        }
        finally
        {
     g.Dispose();
        }
 }
Пример #20
0
        private static string ExtractLongestString(Label label)
        {
            float longestSize = 0;
            string longestLabel = string.Empty;
            foreach (string test in label.Text.Split('\n'))
            {
                float testWidth = label.CreateGraphics().MeasureString(test, label.Font).Width;
                if (testWidth >= longestSize)
                {
                    longestSize = testWidth;
                    longestLabel = test;
                }
            }

            return longestLabel;
        }
Пример #21
0
 private void SetLabelText(Label label, string text)
 {
     if (label.Width > label.CreateGraphics().MeasureString(text+ ": " + FileDescription, label.Font).Width)
         label.Text = text;
     else
         label.Text = Path.GetFileName(text);
     if (FileDescription.Length > 0)
         label.Text += ": " + FileDescription;
 }
Пример #22
0
        /// <summary>
        /// Hộp thoại nhập giá trị
        /// </summary>
        /// <param name="promptText">Nội dung</param>
        /// <param name="title">Tiêu đề</param>
        /// <param name="value">Lưu giá trị người dùng nhập</param>
        /// <returns>Nút người dùng bấm</returns>
        private DialogResult InputBox(string promptText, string title, ref string value)
        {
            Form form = new Form();
            Label label = new Label();
            TextBox textBox = new TextBox();
            Button buttonOk = new Button();
            Button buttonCancel = new Button();

            form.Text = title;
            label.Text = promptText;
            textBox.Text = value;

            buttonOk.Text = "OK";
            buttonCancel.Text = "Cancel";
            buttonOk.DialogResult = DialogResult.OK;
            buttonCancel.DialogResult = DialogResult.Cancel;

            SizeF textSize = label.CreateGraphics().MeasureString(promptText, label.Font);
            if (textSize.Width < 75 * 2 + 30)
                textSize.Width = 75 * 2 + 10;
            label.SetBounds(10, 10, (int)textSize.Width, (int)textSize.Height); //x , y , width , height
            label.AutoSize = false;
            textBox.SetBounds(label.Left, label.Bottom + 5, label.Width, 20);
            buttonOk.SetBounds(label.Right - 75, textBox.Bottom + 5, 75, 23);
            buttonCancel.SetBounds(label.Right - 75*2 - 10, textBox.Bottom + 5, 75, 23);
            textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
            buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
            buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;

            form.ClientSize = new Size(label.Right + 10, buttonOk.Bottom + 10);
            form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
            //form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
            form.FormBorderStyle = FormBorderStyle.FixedDialog;
            form.StartPosition = FormStartPosition.CenterScreen;
            form.MinimizeBox = false;
            form.MaximizeBox = false;
            form.AcceptButton = buttonOk;
            form.CancelButton = buttonCancel;

            DialogResult dialogResult = form.ShowDialog();
            value = textBox.Text;
            return dialogResult;
        }
Пример #23
0
            public FormField(Field f, XDataForm form, int tabIndex)
            {
                m_field = f;
                m_type = f.Type;
                m_var = f.Var;
                m_val = f.Vals;
                m_required = f.IsRequired;
                m_form = form;

                Panel p = null;
                if (m_type != FieldType.hidden)
                {
                    p = new Panel();
                    p.Parent = m_form.pnlFields;
                    p.TabIndex = tabIndex;
                }

                switch (m_type)
                {
                    case FieldType.hidden:
                        break;
                    case FieldType.boolean:
                        CheckBox cb = new CheckBox();
                        cb.Checked = f.BoolVal;
                        cb.Text = null;
                        m_control = cb;
                        break;
                    case FieldType.text_multi:
                        TextBox mtxt = new TextBox();
                        mtxt.Multiline = true;
                        mtxt.ScrollBars = ScrollBars.Vertical;
                        mtxt.Lines = m_val;
                        mtxt.Height = m_form.btnOK.Height * 3;
                        m_control = mtxt;
                        break;
                    case FieldType.text_private:
                        TextBox ptxt = new TextBox();
                        ptxt.Lines = m_val;
                        ptxt.PasswordChar = '*';
                        m_control = ptxt;
                        break;
                    case FieldType.list_single:
                        ComboBox box = new ComboBox();
                        box.DropDownStyle = ComboBoxStyle.DropDownList;
                        box.BeginUpdate();
                        string v = null;
                        if (m_val.Length > 0)
                            v = m_val[0];
                        foreach (Option o in f.GetOptions())
                        {
                            int i = box.Items.Add(o);

                            if (o.Val == v)
                            {
                                box.SelectedIndex = i;
                            }
                        }
                        box.EndUpdate();
                        m_control = box;
                        break;

                    case FieldType.list_multi:
                        //ListBox lb = new ListBox();
                        CheckedListBox lb = new CheckedListBox();
                        //lb.SelectionMode = SelectionMode.MultiExtended;
                        lb.VisibleChanged += new EventHandler(lb_VisibleChanged);
                        m_control = lb;
                        break;

                    case FieldType.jid_single:
                        TextBox jtxt = new TextBox();
                        jtxt.Lines = m_val;
                        jtxt.Validating += new CancelEventHandler(jid_Validating);
                        jtxt.Validated += new EventHandler(jid_Validated);
                        m_control = jtxt;
                        m_form.error.SetIconAlignment(m_control, ErrorIconAlignment.MiddleLeft);
                        break;

                    case FieldType.jid_multi:
                        JidMulti multi = new JidMulti();
                        multi.AddRange(m_val);
                        m_control = multi;
                        break;

                    case FieldType.Fixed:
                        // All of this so that we can detect URLs.
                        // We can't just make it disabled, because then the URL clicked
                        // event handler doesn't fire, and there's no way to set the
                        // text foreground color.
                        // It would be cool to make copy work, but it doesn't work for
                        // labels, either.
                        RichTextBox rich = new RichTextBox();
                        rich.DetectUrls = true;
                        rich.Text = string.Join("\r\n", f.Vals);
                        rich.ScrollBars = RichTextBoxScrollBars.None;
                        rich.Resize += new EventHandler(lbl_Resize);
                        rich.BorderStyle = BorderStyle.None;
                        rich.LinkClicked += new LinkClickedEventHandler(rich_LinkClicked);
                        rich.BackColor = System.Drawing.SystemColors.Control;
                        rich.KeyPress += new KeyPressEventHandler(rich_KeyPress);
                        rich.GotFocus += new EventHandler(rich_GotFocus);
                        rich.AcceptsTab = false;
                        rich.AutoSize = false;
                        m_control = rich;
                        break;
                    default:
                        TextBox txt = new TextBox();
                        txt.Lines = m_val;
                        m_control = txt;
                        break;
                }

                if (m_type != FieldType.hidden)
                {
                    m_control.Parent = p;

                    if (f.Desc != null)
                        form.tip.SetToolTip(m_control, f.Desc);

                    String lblText = "";

                    if (f.Label != "")
                        lblText = f.Label + ":";
                    else if (f.Var != "")
                        lblText = f.Var + ":";

                    if (lblText != "")
                    {
                        m_label = new Label();
                        m_label.Parent = p;
                        m_label.Text = lblText;

                        if (m_required)
                        {
                            m_label.Text = "* " + m_label.Text;
                            m_form.error.SetIconAlignment(m_control, ErrorIconAlignment.MiddleLeft);

                            m_control.Validating += new CancelEventHandler(m_control_Validating);
                            m_control.Validated += new EventHandler(m_control_Validated);
                        }
                        Graphics graphics = m_label.CreateGraphics();
                        SizeF s = m_label.Size;
                        s.Height = 0;
                        int chars;
                        int lines;
                        SizeF textSize = graphics.MeasureString(m_label.Text, m_label.Font, s, StringFormat.GenericDefault, out chars, out lines);
                        m_label.Height = (int) (textSize.Height);

                        if (lines > 1)
                            m_label.TextAlign = ContentAlignment.MiddleLeft;
                        else
                            m_label.TextAlign = ContentAlignment.TopLeft;

                        m_label.Top = 0;
                        p.Controls.Add(m_label);
                        m_control.Location = new Point(m_label.Width + 3, 0);
                        m_control.Width = p.Width - m_label.Width - 6;
                        p.Height = Math.Max(m_label.Height, m_control.Height) + 4;
                    }
                    else
                    {
                        m_control.Location = new Point(0, 0);
                        m_control.Width = p.Width - 6;
                        p.Height = m_control.Height + 4;
                    }
                    m_control.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                    p.Controls.Add(m_control);
                    p.Dock = DockStyle.Top;
                    m_form.pnlFields.Controls.Add(p);

                    if (m_form.m_type != XDataType.form)
                        m_control.Enabled = false;
                }
            }
Пример #24
0
        public EditControl(DynGroupBox xgrp_box, object refobj, string xName, ltext lt_label, ltext lt_val, ltext lt_help)
        {
            m_grp_box = xgrp_box;
            m_lt_help = lt_help;
            this.MinEditBoxWidth = m_grp_box.MinEditBoxWidth;
            this.LeftMargin = m_grp_box.LeftMargin;
            this.RightMargin = m_grp_box.RightMargin;
            this.TopMargin = m_grp_box.TopMargin;
            this.VerticalDistance = m_grp_box.VerticalDistance;
            this.HorisontalDistance = m_grp_box.HorisontalDistance;
            this.lblVerticalOffset = m_grp_box.lblVerticalOffset;
            this.TxtVerticalOffsetToLabel = m_grp_box.VerticalOffsetToLabel;
            this.HorisontallOffsetToLabel = m_grp_box.HorisontallOffsetToLabel;
            this.ColorChanged = m_grp_box.ColorChanged;
            this.ColorNotChanged = m_grp_box.ColorNotChanged;

            m_refobj = refobj;
            m_Name = xName;
            lbl = new Label();
            if (m_refobj is dstring_v)
            {
                if (xName.Equals("MyOrg_Person_Password"))
                {
                    edit_control = new Password.usrc_Password();
                    bool bltValDefined = false;
                    if (lt_val != null)
                    {
                        if (lt_val.s != null)
                        {
                            bltValDefined = true;
                        }
                    }
                    if (bltValDefined)
                    {
                        ((Password.usrc_Password)edit_control).Text = ((Password.usrc_Password)edit_control).LockPassword(lt_val.s);
                        ((dstring_v)m_refobj).v = lt_val.s;
                    }
                    else
                    {
                        edit_control.Text = ((dstring_v)m_refobj).vs;
                    }
                    ((dstring_v)m_refobj).defined = true;
                }
                else
                {
                    edit_control = new TextBox();
                    bool bltValDefined = false;
                    if (lt_val != null)
                    {
                        if (lt_val.s != null)
                        {
                            bltValDefined = true;
                        }
                    }
                    if (bltValDefined)
                    {
                        edit_control.Text = lt_val.s;
                        ((dstring_v)m_refobj).v = lt_val.s;
                    }
                    else
                    {
                        edit_control.Text = ((dstring_v)m_refobj).vs;
                    }
                    ((dstring_v)m_refobj).defined = true;
                }
            }
            else if (m_refobj is dbool_v)
            {
                if (xName.Equals("MyOrg_Person_Gender"))
                {
                    edit_control = new usrc_SelectGender();
                    ((usrc_SelectGender)edit_control).RadioButton1IsTrue = true;
                    ((usrc_SelectGender)edit_control).RadioButton1_Text = lngRPM.s_Male.s;
                    ((usrc_SelectGender)edit_control).RadioButton2_Text = lngRPM.s_Female.s;
                    if (((dbool_v)m_refobj).defined)
                    {
                        ((usrc_SelectGender)edit_control).Checked = ((dbool_v)m_refobj).v;
                    }
                }
                else
                {
                    edit_control = new CheckBox();
                    ((CheckBox)edit_control).Text = "";
                    if (((dbool_v)m_refobj).defined)
                    {
                        ((CheckBox)edit_control).Checked = ((dbool_v)m_refobj).v;
                    }
                }
            }
            else if (m_refobj is dDateTime_v)
            {
                edit_control = new DateTimePicker();
                edit_control.Text = "";
                ((DateTimePicker)edit_control).Value = DateTime.Now;
                ((dDateTime_v)m_refobj).v = ((DateTimePicker)edit_control).Value;
            }
            else if (m_refobj is dshort_v)
            {
                edit_control = new usrc_NumericUpDown(false);
                ((usrc_NumericUpDown)edit_control).Minimum = 0;
                ((usrc_NumericUpDown)edit_control).Maximum = 100000;
                ((usrc_NumericUpDown)edit_control).Value = Convert.ToDecimal(((dshort_v)m_refobj).v);
                ((dshort_v)m_refobj).v = Convert.ToInt16(((usrc_NumericUpDown)edit_control).Value);
            }
            else if (m_refobj is dbyte_array_v)
            {
                edit_control = new usrc_GetImage();
                if (m_refobj!=null)
                {
                    if (((dbyte_array_v)m_refobj).v != null)
                    {
                        ImageConverter ic = new ImageConverter();
                        ((usrc_GetImage)edit_control).Image = (Image)ic.ConvertFrom(((dbyte_array_v)m_refobj).v);
                        Image_Hash = ((usrc_GetImage)edit_control).Image_Hash;
                    }
                }
            }
            else
            {
                LogFile.Error.Show("ERROR:EditControl:unsuported type: m_refobj type =" + m_refobj.GetType().ToString());
                return;
            }

            lbl.Name = "lbl_" + m_grp_box.Name + "_" + m_Name;
            lbl.Font = m_grp_box.Font;
            edit_control.Name = "txt_" + m_grp_box.Name + "_" + m_Name;
            edit_control.Font = m_grp_box.Font;
            lbl.AutoSize = false;
            lbl.Text = lt_label.s + ":";
            SizeF size_lbl = lbl.CreateGraphics().MeasureString(lbl.Text, lbl.Font);
            SizeF size_txt = lbl.CreateGraphics().MeasureString(edit_control.Text, edit_control.Font);
            lbl.Width = (int)Math.Ceiling(size_lbl.Width);
            lbl.Height = (int)Math.Ceiling(size_lbl.Height);
            if ((m_refobj is dstring_v))
            {
                edit_control.Width = MinEditBoxWidth;
                if (edit_control is TextBox)
                {
                    int txt_calculated_width = (int)Math.Ceiling(size_txt.Width) + 4;
                    if (edit_control.Width < txt_calculated_width)
                    {
                        edit_control.Width = txt_calculated_width;
                    }
                }
                else if (edit_control is Password.usrc_Password)
                {
                    edit_control.Width = 128;
                }
            }

            this.Width = lbl.Width + m_HorisontallOffsetToLabel + edit_control.Width;
            if (m_grp_box.EditControlsList == null)
            {
                m_grp_box.EditControlsList = new List<EditControl>();
            }
            m_grp_box.EditControlsList.Add(this);
            int EditControlsList_Count = m_grp_box.EditControlsList.Count;
            if (EditControlsList_Count == 1)
            {
                this.pPrev = null;
                this.pNext = null;
            }
            else if (EditControlsList_Count > 1)
            {
                this.pPrev = m_grp_box.EditControlsList[EditControlsList_Count - 2];
                m_grp_box.EditControlsList[EditControlsList_Count - 2].pNext = this;
                this.pNext = null;
            }
            m_grp_box.Controls.Add(lbl);
            m_grp_box.Controls.Add(edit_control);
            if (m_grp_box.tooltip != null)
            {
                m_grp_box.tooltip.SetToolTip(edit_control, lt_help.s);
                m_grp_box.tooltip.SetToolTip(lbl, lt_help.s);
            }
        }
Пример #25
0
        public void RefreshLoot() {
            foreach (Control c in createdControls) {
                this.Controls.Remove(c);
                c.Dispose();
            }
            createdControls.Clear();
            if (page < 0) page = 0;

            int base_x = 20, base_y = 30;
            int x = 0, y = 0;
            int item_spacing = 4;
            Size item_size = new Size(32, 32);
            int max_x = MainForm.mainForm.getSettingInt("LootFormWidth");
            if (max_x < minLootWidth) max_x = minLootWidth;
            int width_x = max_x + item_spacing * 2;

            // add a tooltip that displays the actual droprate when you mouseover
            ToolTip value_tooltip = new ToolTip();
            value_tooltip.AutoPopDelay = 60000;
            value_tooltip.InitialDelay = 500;
            value_tooltip.ReshowDelay = 0;
            value_tooltip.ShowAlways = true;
            value_tooltip.UseFading = true;
            long total_value = 0;
            int currentPage = 0;
            bool prevPage = page > 0;
            bool nextPage = false;

            averageGold = 0;
            foreach(KeyValuePair<Creature, int> tpl in creatures) {
                double average = 0;
                foreach(ItemDrop dr in tpl.Key.itemdrops) {
                    Item it = MainForm.getItem(dr.itemid);
                    if (!it.discard && it.GetMaxValue() > 0 && dr.percentage > 0) {
                        average += ((dr.min + dr.max) / 2.0) * (dr.percentage / 100.0) * it.GetMaxValue();
                    }
                }
                Console.WriteLine(average);
                Console.WriteLine(tpl.Value);
                averageGold += (int)(average * tpl.Value);
            }

            foreach (Tuple<Item, int> tpl in items) {
                total_value += tpl.Item1.GetMaxValue() * tpl.Item2;
            }
            foreach (Tuple<Item, int> tpl in items) {
                Item item = tpl.Item1;
                int count = tpl.Item2;
                while (count > 0) {
                    if (base_x + x >= (max_x - item_size.Width - item_spacing)) {
                        x = 0;
                        if (y + item_size.Height + item_spacing > pageHeight) {
                            currentPage++;
                            if (currentPage > page) {
                                nextPage = true;
                                break;
                            } else {
                                y = 0;
                            }
                        } else {
                            y = y + item_size.Height + item_spacing;
                        }
                    }
                    int mitems = 1;
                    if (item.stackable || count > 100) mitems = Math.Min(count, 100);
                    count -= mitems;
                    if (currentPage == page) {
                        PictureBox picture_box = new PictureBox();
                        picture_box.Location = new System.Drawing.Point(base_x + x, base_y + y);
                        picture_box.Name = item.GetName();
                        picture_box.Size = new System.Drawing.Size(item_size.Width, item_size.Height);
                        picture_box.TabIndex = 1;
                        picture_box.TabStop = false;
                        if (item.stackable || mitems > 1) {
                            picture_box.Image = LootDropForm.DrawCountOnItem(item, mitems);
                        } else {
                            picture_box.Image = item.GetImage();
                        }

                        picture_box.SizeMode = PictureBoxSizeMode.StretchImage;
                        picture_box.BackgroundImage = MainForm.item_background;
                        picture_box.Click += openItemBox;
                        long individualValue = Math.Max(item.actual_value, item.vendor_value);
                        value_tooltip.SetToolTip(picture_box, System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(item.displayname) + " value: " + (individualValue >= 0 ? (individualValue * mitems).ToString() : "Unknown"));
                        createdControls.Add(picture_box);
                        this.Controls.Add(picture_box);
                    }

                    x += item_size.Width + item_spacing;
                }
                if (currentPage > page) {
                    break;
                }
            }
            if (page > currentPage) {
                page = currentPage;
                RefreshLoot();
                return;
            }

            y = y + item_size.Height + item_spacing;
            if (prevPage) {
                PictureBox prevpage = new PictureBox();
                prevpage.Location = new Point(10, base_y + y);
                prevpage.Size = new Size(97, 23);
                prevpage.Image = MainForm.prevpage_image;
                prevpage.BackColor = Color.Transparent;
                prevpage.SizeMode = PictureBoxSizeMode.StretchImage;
                prevpage.Click += Prevpage_Click;
                this.Controls.Add(prevpage);
                createdControls.Add(prevpage);
            }
            if (nextPage) {
                PictureBox nextpage = new PictureBox();
                nextpage.Location = new Point(width_x - 108, base_y + y);
                nextpage.Size = new Size(98, 23);
                nextpage.BackColor = Color.Transparent;
                nextpage.Image = MainForm.nextpage_image;
                nextpage.SizeMode = PictureBoxSizeMode.StretchImage;
                nextpage.Click += Nextpage_Click;
                this.Controls.Add(nextpage);
                createdControls.Add(nextpage);
            }
            if (prevPage || nextPage) y += 23;

            x = 0;
            base_x = 5;
            Size creature_size = new Size(1, 1);
            Size labelSize = new Size(1, 1);

            foreach (KeyValuePair<Creature, int> tpl in creatures) {
                Creature creature = tpl.Key;
                creature_size.Width = Math.Max(creature_size.Width, creature.GetImage().Width);
                creature_size.Height = Math.Max(creature_size.Height, creature.GetImage().Height);
            }
            {
                int i = 0;
                foreach (Creature cr in creatures.Keys.OrderByDescending(o => creatures[o] * (1 + o.experience)).ToList<Creature>()) {
                    Creature creature = cr;
                    int killCount = creatures[cr];
                    if (x >= max_x - creature_size.Width - item_spacing * 2) {
                        x = 0;
                        y = y + creature_size.Height + 23;
                        if (y > maxCreatureHeight) {
                            break;
                        }
                    }
                    int xoffset = (creature_size.Width - creature.GetImage().Width) / 2;
                    int yoffset = (creature_size.Height - creature.GetImage().Height) / 2;

                    Label count = new Label();
                    count.Text = killCount.ToString() + "x";
                    count.Font = loot_font;
                    count.Size = new Size(1, 10);
                    count.Location = new Point(base_x + x + xoffset, base_y + y + creature_size.Height);
                    count.AutoSize = true;
                    count.TextAlign = ContentAlignment.MiddleCenter;
                    count.ForeColor = Color.FromArgb(191, 191, 191);
                    count.BackColor = Color.Transparent;

                    int measured_size = (int)count.CreateGraphics().MeasureString(count.Text, count.Font).Width;
                    int width = Math.Max(measured_size, creature.GetImage().Width);
                    PictureBox picture_box = new PictureBox();
                    picture_box.Location = new System.Drawing.Point(base_x + x + xoffset, base_y + y + yoffset + (creature_size.Height - creature.GetImage().Height) / 2);
                    picture_box.Name = creature.GetName();
                    picture_box.Size = new System.Drawing.Size(creature.GetImage().Width, creature.GetImage().Height);
                    picture_box.TabIndex = 1;
                    picture_box.TabStop = false;
                    picture_box.Image = creature.GetImage();
                    picture_box.SizeMode = PictureBoxSizeMode.StretchImage;
                    picture_box.Click += openCreatureDrops;
                    picture_box.BackColor = Color.Transparent;

                    if (width > creature.GetImage().Width) {
                        picture_box.Location = new Point(picture_box.Location.X + (width - creature.GetImage().Width) / 2, picture_box.Location.Y);
                    } else {
                        count.Location = new Point(count.Location.X + (width - measured_size) / 2, count.Location.Y);
                    }

                    labelSize = count.Size;

                    i++;
                    x += width + xoffset;
                    createdControls.Add(picture_box);
                    createdControls.Add(count);
                    this.Controls.Add(picture_box);
                    this.Controls.Add(count);
                }
                y = y + creature_size.Height + labelSize.Height * 2;
            }

            int xPosition = width_x - totalValueValue.Size.Width - 5;
            y = base_y + y + item_spacing + 10;
            huntNameLabel.Text = hunt.name.ToString();
            totalValueLabel.Location = new Point(5, y);
            totalValueValue.Location = new Point(xPosition, y);
            totalValueValue.Text = total_value.ToString();
            value_tooltip.SetToolTip(totalValueValue, String.Format("Average gold for these creature kills: {0} gold.", averageGold));
            totalExpLabel.Location = new Point(5, y += 20);
            totalExpValue.Location = new Point(xPosition, y);
            totalExpValue.Text = hunt.totalExp.ToString();
            totalTimeLabel.Location = new Point(5, y += 20);
            totalTimeValue.Location = new Point(xPosition, y);

            long totalSeconds = (long)hunt.totalTime;
            string displayString = "";
            if (totalSeconds >= 3600) {
                displayString += (totalSeconds / 3600).ToString() + "h ";
                totalSeconds = totalSeconds % 3600;
            }
            if (totalSeconds >= 60) {
                displayString += (totalSeconds / 60).ToString() + "m ";
                totalSeconds = totalSeconds % 60;
            }
            displayString += totalSeconds.ToString() + "s";

            totalTimeValue.Text = displayString;
            y += 20;


            int widthSize = width_x / 3 - 5;
            lootButton.Size = new Size(widthSize, lootButton.Size.Height);
            lootButton.Location = new Point(5, y);
            allLootButton.Size = new Size(widthSize, lootButton.Size.Height);
            allLootButton.Location = new Point(7 + widthSize, y);
            rawLootButton.Size = new Size(widthSize, lootButton.Size.Height);
            rawLootButton.Location = new Point(10 + 2 * widthSize, y);

            y += allLootButton.Size.Height + 2;

            huntNameLabel.Size = new Size(width_x, huntNameLabel.Size.Height);
            this.Size = new Size(width_x, y + 5);
            lootLarger.Location = new Point(Size.Width - lootLarger.Size.Width - 4, 4);
            lootSmaller.Location = new Point(Size.Width - 2 * lootLarger.Size.Width - 4, 4);
        }
Пример #26
0
        /// <summary>
        /// Adds a label at the specified position, with the specified text and tag.
        /// </summary>
        /// <param name="pos">The position to add the label on.</param>
        /// <param name="text">The text to place on the label.</param>
        /// <param name="index">The index to store in the tag of the label.</param>
        /// <param name="preview">A value indicating whether this label is used as a size preview and only
        /// its basic properties should be filled.</param>
        /// <returns>The width of the created label.</returns>
        private int AddLabel(int pos, string text, int index, bool preview = false)
        {
            var label = new Label();

            // Layout of the label.
            var textSize = label.CreateGraphics().MeasureString(text, label.Font);
            label.AutoSize = true;
            this.Controls.Add(label);
            label.MinimumSize = new Size(0, 0);
            label.Text = text;
            label.BorderStyle = BorderStyle.FixedSingle;
            label.Location = new Point(pos, 0);

            // When the label is not being used just for calculating the width, also add all the other
            // relevant information.
            if (!preview)
            {
                label.Tag = index;
                label.Cursor = Cursors.Hand;
                label.Height = (int)Math.Ceiling(textSize.Height);

                // Events on the label.
                label.MouseEnter += MouseEnter;
                label.MouseLeave += MouseLeave;
                label.MouseClick += MouseClick;
            }

            return label.Width - 2;
        }
Пример #27
0
 private static int computeLabelWidth(Label l)
 {
     Graphics g = l.CreateGraphics();
     int result = (int)g.MeasureString(l.Text, l.Font).Width + l.Margin.Horizontal;
     g.Dispose();
     return result;
 }
        private Label getKeyLabel(String key)
        {
            Label newLabel = new Label();
            Boolean isText = true;

            if (!key.Equals("+"))
            {
                newLabel.BackColor = System.Drawing.Color.White;
                newLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;

                switch (key)
                {
                    case "UP":
                        newLabel.Image = global::ACPAddIn.Properties.Resources.up;
                        isText = false;
                        break;
                    case "DOWN":
                        newLabel.Image = global::ACPAddIn.Properties.Resources.down;
                        isText = false;
                        break;
                    case "LEFT":
                        newLabel.Image = global::ACPAddIn.Properties.Resources.left;
                        isText = false;
                        break;
                    case "RIGHT":
                        newLabel.Image = global::ACPAddIn.Properties.Resources.right;
                        isText = false;
                        break;
                    case "COMMA":
                        newLabel.Text = "<";
                        break;
                    case "PERIOD":
                        newLabel.Text = ">";
                        break;
                    default:
                        newLabel.Text = key;
                        break;
                }

                int width=22;

                if (isText)
                {
                    Graphics g = newLabel.CreateGraphics();
                    width = (int)g.MeasureString(newLabel.Text, newLabel.Font).Width;
                    g.Dispose();
                    width += 5;
                }

                // Make the label a square if the width is too small
                if (width < 26)
                {
                    width = 26;
                }

                newLabel.Size = new System.Drawing.Size(width, 26);

                newLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            }
            else
            {
                newLabel.Size = new System.Drawing.Size(10, 26);
                newLabel.Text = key;
                newLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            }

            return newLabel;
        }
Пример #29
0
		/// <summary>
		/// Calculates the maximum extent of a text that can fit in the given label (without wrapping).
		/// </summary>
		/// <param name="str">The full text to try fitting</param>
		/// <param name="label">The label to fit the text to</param>
		/// <returns>As much of the text as will fit (including "..." if it's incomplete)</returns>
		public static string FitTextToLabel(string str, Label label)
		{
			if (string.IsNullOrEmpty(str))
			{
				return str;		// no text: it all fits
			}
			int labelWidth = label.Width - label.Padding.Horizontal;
			if (labelWidth < 1)
			{
				return string.Empty;	// nothing will fit
			}

			using (Graphics graphics = label.CreateGraphics())
			{
				SizeF size = graphics.MeasureString(str, label.Font);
				if (size.Width <= labelWidth)
				{
					return str;		// it all fits
				}

				string fittedText = string.Empty;
				// Estimate the length required
				int length = (int) (str.Length * labelWidth / size.Width);
				while (size.Width > labelWidth && length > 0)
				{
					fittedText = PathCompactPath(str, length);
					size = graphics.MeasureString(fittedText, label.Font);
					--length;
				}

				// See if we can extend the text
				string longerText = fittedText;
				for (length = fittedText.Length + 1; size.Width < labelWidth; ++length)
				{
					fittedText = longerText;    // the longest fit so far
					longerText = PathCompactPath(str, length);
					size = graphics.MeasureString(longerText, label.Font);
				}

				return fittedText;
			}
		}
        public void OnClick(object obj, EventArgs click)
        {
            if (!(this.Checked)) {
                if (this.m_Connected) {
                    using (Synchronizer.Lock(this.m_ClassroomManager.Classroom.SyncRoot))
                        this.m_ClassroomManager.Classroom.Connected = false;
                    this.Text = Strings.ConnectToTCPServer;
                    this.m_Connected = false;

                }
                return;
            }

            if (this.m_ClassroomManager == null)
                return;

            using (Synchronizer.Lock(this.m_Model.ViewerState.SyncRoot)) {
                this.m_Model.ViewerState.ManualConnectionButtonName = this.Text;
            }
            if (this.m_Connected) {
                using (Synchronizer.Lock(this.m_ClassroomManager.Classroom.SyncRoot))
                    this.m_ClassroomManager.Classroom.Connected = false;
                this.Text = Strings.ConnectToTCPServer;
                this.m_Connected = false;
            }

            Label label = new Label();
            label.FlatStyle = FlatStyle.System;
            label.Font = Model.Viewer.ViewerStateModel.StringFont2;
            label.Text = Strings.ServerNameAddress;
            using (Graphics graphics = label.CreateGraphics())
                label.ClientSize = Size.Add(new Size(10, 0),
                    graphics.MeasureString(label.Text, label.Font).ToSize());
            label.Location = new Point(5, 5);

            Form form = new Form();
            form.Font = Model.Viewer.ViewerStateModel.FormFont;
            form.Text = Strings.ConnectToTCPServer;
            form.ClientSize = new Size(label.Width * 3, 2 * form.ClientSize.Height);
            form.FormBorderStyle = FormBorderStyle.FixedDialog;

            TextBox addressInput = new TextBox();
            addressInput.Font = Model.Viewer.ViewerStateModel.StringFont2;
            addressInput.Size = new Size(((int)(form.ClientSize.Width - (label.Width * 1.2))), this.Font.Height);
            addressInput.Location = new Point(((int)(label.Right * 1.1)), label.Top);

            using (Synchronizer.Lock(this.m_Model.ViewerState.SyncRoot)) {
                if (this.m_Model.ViewerState.TCPaddress != "" && this.m_Model.ViewerState.TCPaddress.Length != 0) {
                    string addr = this.m_Model.ViewerState.TCPaddress;
                    addressInput.Text = addr;
                }
            }

            Label label2 = new Label();
            label2.FlatStyle = FlatStyle.System;
            label2.Font = Model.Viewer.ViewerStateModel.StringFont2;
            label2.Text = Strings.Port + " (default: " + TCPServer.DefaultPort.ToString() + ")";
            using (Graphics graphics = label.CreateGraphics())
                label2.ClientSize = Size.Add(new Size(10, 0),
                    graphics.MeasureString(label2.Text, label2.Font).ToSize());
            label2.Location = new Point(5, Math.Max(addressInput.Bottom, label.Bottom) + 10);

            TextBox portInput = new TextBox();
            portInput.Font = Model.Viewer.ViewerStateModel.StringFont2;
            portInput.Size = new Size((4 / 3) * sizeConst, sizeConst / 2);
            portInput.Location = new Point(addressInput.Left, label2.Top);

            using (Synchronizer.Lock(this.m_Model.ViewerState.SyncRoot)) {
                if (this.m_Model.ViewerState.TCPport != 0) {
                    portInput.Text = this.m_Model.ViewerState.TCPport.ToString();
                }
                else {
                    portInput.Text = TCPServer.DefaultPort.ToString();
                }
            }

            Button okay = new Button();
            okay.FlatStyle = FlatStyle.System;
            okay.Font = Model.Viewer.ViewerStateModel.StringFont;
            okay.Text = Strings.OK;
            okay.Width = (addressInput.Right - label.Left) / 2 - 5;
            okay.Location = new Point(label.Left, Math.Max(portInput.Bottom, label2.Bottom) + 10);

            Button cancel = new Button();
            cancel.FlatStyle = FlatStyle.System;
            cancel.Font = Model.Viewer.ViewerStateModel.StringFont;
            cancel.Text = Strings.Cancel;
            cancel.Width = okay.Width;
            cancel.Location = new Point(okay.Right + 10, okay.Top);

            EventHandler connect = delegate(object source, EventArgs args) {

                    string address = addressInput.Text;

                using (Synchronizer.Lock(this.m_Model.ViewerState.SyncRoot)) {
                    this.m_Model.ViewerState.TCPaddress = address;
                }
                try {
                    IPAddress ipaddress;
                    if (!IPAddress.TryParse(address, out ipaddress)) {
                        IPHostEntry entry = Dns.GetHostEntry(address);
                        ipaddress = entry.AddressList[0];
                        if (entry.AddressList.Length > 1) {
                            //This happened once on the UW network.  I think it was a case of broken DNS.
                            Trace.WriteLine("Warning: Multiple Server IP addresses found. CP3 is arbitrarily choosing one.");
                        }
                    }
                    int port = 0;
                    if (!Int32.TryParse(portInput.Text, out port)) {
                        port = TCPServer.DefaultPort;
                    }
                    using (Synchronizer.Lock(this.m_Model.ViewerState.SyncRoot)) {
                        this.m_Model.ViewerState.TCPport = port;
                    }
                    IPEndPoint ep = new IPEndPoint(ipaddress, port);
                    this.m_ClassroomManager.RemoteServerEndPoint = ep;
                    using (Synchronizer.Lock(m_ClassroomManager.Classroom.SyncRoot))
                        m_ClassroomManager.Classroom.Connected = true;
                    this.m_Connected = true;
                    form.Visible = false;
                }
                catch (Exception e) {
                    MessageBox.Show(
                        string.Format("Classroom Presenter was unable to connect to\n\n"
                            + "\t\"{0}\"\n\nfor the following reason:\n\n{1}",
                            address, e.Message),
                        "Connection Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    this.m_Connected = false;
                }
            };

            /*host.KeyPress += delegate(object source, KeyPressEventArgs args) {
                if (args.KeyChar == '\r')
                    connect(source, EventArgs.Empty);
                }*/

            okay.Click += connect;
            okay.DialogResult = DialogResult.OK;

            form.CancelButton = cancel;
            cancel.DialogResult = DialogResult.Cancel;
            cancel.Click += delegate(object source, EventArgs args) {
                this.m_Connected = false;
                form.Visible = false;
            };

            form.ClientSize = new Size(form.ClientSize.Width, Math.Max(okay.Bottom, cancel.Bottom) + 5);

            form.Controls.Add(label);
            form.Controls.Add(addressInput);
            form.Controls.Add(label2);
            form.Controls.Add(portInput);
            form.Controls.Add(okay);
            form.Controls.Add(cancel);

            //Find the startup form which is the proper owner of the modal dialog
            Control c = this;
            while (c.Parent != null) {
                c = c.Parent;
            }

            DialogResult dr = form.ShowDialog(c);
            form.Dispose();
            if (dr == DialogResult.Cancel) {
                //This causes another call to OnClick but it should return without doing anything.
                this.Checked = false;
            }
        }
        private static void AddControls(bool displayOnly)
        {
            try
            {

                s_tbCntlDisplay.TabPages.Clear();
                s_tbCntlDisplay.Controls.Clear();

                //Exit if the layer is not found
                if (v_ViewerLayer == null)
                    return;
                if (v_ViewerLayer.FeatureClass == null)
                    return;

                int pLeftPadding = 10;

                //Clear out the controls from the container
               // s_tbCntlDisplay.TabPages.Clear();
              //  s_tbCntlDisplay.Controls.Clear();
                TabPage pTbPg = new TabPage();
                s_tbCntlDisplay.TabPages.Add(pTbPg);

                //Controls to display attributes
                //Dim pTbPg As TabPage = Nothing
                TextBox pTxtBox = default(TextBox);
                Label pLbl = default(Label);
                NumericUpDown pNumBox = default(NumericUpDown);
                System.Windows.Forms.Button pBtn = null;
                ComboBox pCBox = default(ComboBox);
                RadioButton pRDButton = default(RadioButton);

                DateTimePicker pDateTime = default(DateTimePicker);
                //Spacing between each control
               // int intCtrlSpace = 5;
                //Spacing between a lable and a control
                //int intLabelCtrlSpace = 0;

                //Set the width of each control
                //   Dim my.Globals.Constants.c_ControlWidth As Integer = 50
                //used for sizing text, only used when text is larger then display
                Graphics g = default(Graphics);
                SizeF s = default(SizeF);

                //Used to loop through featurelayer
                IFields pDCs = default(IFields);
                IField pDc = default(IField);
                int pSubTypeDefValue = 0;

                //Get the columns for hte layer
                pDCs = v_ViewerLayer.FeatureClass.Fields;
                ISubtypes pSubType = (ISubtypes)v_ViewerLayer.FeatureClass;
                if (pSubType.HasSubtype)
                {
                    pSubTypeDefValue = pSubType.DefaultSubtypeCode;
                    //pfl.Columns(pfl.SubtypeColumnIndex).DefaultValue
                }

                //Field Name
                string strfld = null;
                //Field Alias
                string strAli = null;

                IDomain pDom = default(IDomain);
                for (int i = 0; i <= pDCs.FieldCount - 1; i++)
                {
                    pDc = (IField)pDCs.get_Field(i);
                    ILayerFields pLayerFields = default(ILayerFields);
                    IFieldInfo pFieldInfo = default(IFieldInfo);

                    pLayerFields = (ILayerFields)v_ViewerLayer;
                    pFieldInfo = pLayerFields.get_FieldInfo(pLayerFields.FindField(pDc.Name));
                    //  pFieldInfo.Visible = False

                    if (pFieldInfo.Visible == false)
                    {

                    }
                    else
                    {

                        pDom = null;

                        //Get the field names
                        strfld = pDc.Name;
                        strAli = pDc.AliasName;

                        //Check the field types

                        if (v_ViewerLayer.FeatureClass.ShapeFieldName == strfld ||
                            v_ViewerLayer.FeatureClass.OIDFieldName == strfld ||
                            (strfld).ToUpper() == ("shape.len").ToUpper() ||
                           (strfld).ToUpper() == ("shape.area").ToUpper() ||
                           (strfld).ToUpper() == ("shape_length").ToUpper() ||
                           (strfld).ToUpper() == ("shape_len").ToUpper() ||
                           (strfld).ToUpper() == ("shape_area").ToUpper() ||
                           (strfld).ToUpper() == ("LASTUPDATE").ToUpper() ||
                           (strfld).ToUpper() == ("LASTEDITOR").ToUpper())
                        {

                        }
                        else if (displayOnly)
                        {

                            //Create a lable for the field name
                            pLbl = new Label();
                            //Apply the field alias to the field name
                            pLbl.Text = strAli;
                            //Link the field to the name of the control
                            pLbl.Name = "lblEdit" + strfld;
                            //Add the control at the determined Location
                            pLbl.Left = 0;

                            pLbl.Top = 0;
                            //Apply global font
                            pLbl.Font = c_FntLbl;
                            //Create a graphics object to messure the text
                            g = pLbl.CreateGraphics();
                            s = g.MeasureString(pLbl.Text, pLbl.Font);

                            pLbl.Height = Convert.ToInt32(s.Height);
                            //If the text is larger then the control, truncate the control
                            if (s.Width >= c_ControlWidth)
                            {
                                pLbl.Width = c_ControlWidth;
                                //Use autosize if it fits
                            }
                            else
                            {
                                pLbl.AutoSize = true;
                            }

                            //Create a new control to display the attributes
                            pTxtBox = new TextBox();

                            //Tag the control with the field it represents
                            pTxtBox.Tag = (strfld).Trim();
                            //Name the field with the field name
                            pTxtBox.Name = "txtEdit" + strfld;
                            //Locate the control on the display
                            pTxtBox.Left = 0;
                            // pTxtBox.Enabled = False
                            pTxtBox.BackColor = Color.White;
                            pTxtBox.ReadOnly = true;

                            pTxtBox.Width = c_ControlWidth;
                            if (pDc.Type == esriFieldType.esriFieldTypeString)
                            {
                                //Make the box taller if it is a long field
                                if (pDc.Length > 125)
                                {
                                    pTxtBox.Multiline = true;
                                    pTxtBox.Height = pTxtBox.Height * 3;

                                }

                            }
                            if (pDc.Length > 0)
                            {
                                pTxtBox.MaxLength = pDc.Length;
                            }

                            //Apply global font
                            pTxtBox.Font = c_Fnt;

                            //Group into panels to assist resizing
                            Panel pPnl = new Panel();
                            pPnl.BorderStyle = System.Windows.Forms.BorderStyle.None;

                            pLbl.Top = 0;
                            pTxtBox.Top = 5 + pLbl.Height;
                            pPnl.Width = c_ControlWidth;
                            pPnl.Margin = new Padding(0);
                            pPnl.Padding = new Padding(0);

                            pPnl.Top = 0;
                            pPnl.Left = 0;
                            pPnl.Height = pTxtBox.Height + pLbl.Height + 10;
                            pPnl.Controls.Add(pLbl);
                            pPnl.Controls.Add(pTxtBox);
                            pTbPg.Controls.Add(pPnl);

                            //Reserved Columns
                        }
                        else if (pSubType.SubtypeFieldName == strfld)
                        {
                            //Create a lable for the field name
                            pLbl = new Label();
                            //Apply the field alias to the field name
                            pLbl.Text = strAli + " (Set This Value First)";
                            //Link the field to the name of the control
                            pLbl.Name = "lblEdit" + strfld;

                            //Add the control at the determined Location

                            pLbl.Left = 0;

                            pLbl.Top = 0;
                            pLbl.ForeColor = Color.Blue;

                            //Apply global font
                            pLbl.Font = c_FntLbl;
                            //Create a graphics object to messure the text
                            g = pLbl.CreateGraphics();
                            s = g.MeasureString(pLbl.Text, pLbl.Font);

                            pLbl.Height = Convert.ToInt32(s.Height);
                            //If the text is larger then the control, truncate the control
                            if (s.Width >= c_ControlWidth)
                            {
                                pLbl.Width = c_ControlWidth;
                                //Use autosize if it fits
                            }
                            else
                            {
                                pLbl.AutoSize = true;
                            }

                            if (Globals.SubtypeCount((ISubtypes)pSubType.Subtypes) == 2)
                            {
                                CustomPanel pNewGpBox = new CustomPanel();
                                pNewGpBox.Tag = strfld;
                                pNewGpBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
                                pNewGpBox.BackColor = Color.White;
                                //  pNewGpBox.BorderColor = Pens.LightGray

                                pNewGpBox.Width = c_ControlWidth;
                                pNewGpBox.Top = 0;
                                pNewGpBox.Left = 0;

                                pRDButton = new RadioButton();
                                pRDButton.Font = c_Fnt;
                                pRDButton.Name = "Rdo1Sub";
                                string codeVal = "";
                                string displayVal = "";
                                Globals.SubtypeValuesAtIndex(0, (ISubtypes)pSubType, ref codeVal, ref displayVal);
                                pRDButton.Tag = codeVal;

                                pRDButton.Text = displayVal;

                                pRDButton.Left = pLeftPadding;

                                pRDButton.AutoSize = true;
                                pNewGpBox.Controls.Add(pRDButton);

                                pNewGpBox.Height = pRDButton.Height + 12;
                                pRDButton.Top = pNewGpBox.Height / 2 - pRDButton.Height / 2 - 2;

                                pRDButton = new RadioButton();
                                pRDButton.Font = c_Fnt;
                                pRDButton.Name = "Rdo2Sub";
                                Globals.SubtypeValuesAtIndex(1, pSubType, ref codeVal, ref displayVal);

                                pRDButton.Tag = codeVal;
                                pRDButton.Text = displayVal;
                                pRDButton.Left = pNewGpBox.Width / 2;

                                pRDButton.AutoSize = true;
                                pNewGpBox.Controls.Add(pRDButton);
                                pRDButton.Top = pNewGpBox.Height / 2 - pRDButton.Height / 2 - 2;

                                Panel pPnl = new Panel();
                                pPnl.BorderStyle = System.Windows.Forms.BorderStyle.None;

                                pLbl.Top = 0;
                                pNewGpBox.Top = pLbl.Height + 5;

                                pPnl.Width = c_ControlWidth;
                                pPnl.Margin = new Padding(0);
                                pPnl.Padding = new Padding(0);

                                pPnl.Top = 0;
                                pPnl.Left = 0;
                                pPnl.Height = pNewGpBox.Height + pLbl.Height + 10;
                                pPnl.Controls.Add(pLbl);
                                pPnl.Controls.Add(pNewGpBox);

                                pTbPg.Controls.Add(pPnl);

                                pNewGpBox = null;
                                //  pPf = Nothing

                            }
                            else
                            {
                                pCBox = new ComboBox();
                                pCBox.Tag = strfld;
                                pCBox.Name = "cboEdt" + strfld;
                                pCBox.Left = 0;
                                pCBox.Top = 0;
                                pCBox.Width = c_ControlWidth;
                                pCBox.Height = pCBox.Height + 5;
                                pCBox.DropDownStyle = ComboBoxStyle.DropDownList;

                                pCBox.Font = c_Fnt;
                                pCBox.DataBindings.DefaultDataSourceUpdateMode = DataSourceUpdateMode.Never;

                                pCBox.DataSource = Globals.SubtypeToList(pSubType);
                                pCBox.DisplayMember = "getDisplay";
                                pCBox.ValueMember = "getValue";
                                // pCmdBox.MaxLength = pDc.Length

                                pCBox.SelectionChangeCommitted += cmbSubTypChange_Click;

                                Panel pPnl = new Panel();
                                pPnl.BorderStyle = System.Windows.Forms.BorderStyle.None;

                                pLbl.Top = 0;
                                pCBox.Top = pLbl.Height + 5;

                                pPnl.Width = c_ControlWidth;
                                pPnl.Margin = new Padding(0);
                                pPnl.Padding = new Padding(0);

                                pPnl.Top = 0;
                                pPnl.Left = 0;
                                pPnl.Height = pCBox.Height + pLbl.Height + 15;
                                pPnl.Controls.Add(pLbl);
                                pPnl.Controls.Add(pCBox);

                                pTbPg.Controls.Add(pPnl);
                                string codeVal = "";
                                string displayVal = "";
                                Globals.SubtypeValuesAtIndex(0, (ISubtypes)pSubType, ref codeVal, ref displayVal);

                                pCBox.Text = displayVal;

                            }

                        }
                        else
                        {

                            if (pSubType.HasSubtype)
                            {
                                pDom = pSubType.get_Domain(pSubTypeDefValue, pDc.Name);

                            }
                            else
                            {
                                pDom = pDc.Domain;

                            }
                            //No Domain Found

                            if (pDom == null)
                            {

                                if (pDc.Type == esriFieldType.esriFieldTypeString || pDc.Type == esriFieldType.esriFieldTypeDouble || pDc.Type == esriFieldType.esriFieldTypeInteger || pDc.Type == esriFieldType.esriFieldTypeSingle || pDc.Type == esriFieldType.esriFieldTypeSmallInteger)
                                {
                                    //Create a lable for the field name
                                    pLbl = new Label();
                                    //Apply the field alias to the field name
                                    pLbl.Text = strAli;
                                    //Link the field to the name of the control
                                    pLbl.Name = "lblEdit" + strfld;
                                    //Add the control at the determined Location
                                    pLbl.Left = 0;

                                    pLbl.Top = 0;
                                    //Apply global font
                                    pLbl.Font = c_FntLbl;
                                    //Create a graphics object to messure the text
                                    g = pLbl.CreateGraphics();
                                    s = g.MeasureString(pLbl.Text, pLbl.Font);

                                    pLbl.Height = Convert.ToInt32(s.Height);
                                    //If the text is larger then the control, truncate the control
                                    if (s.Width >= c_ControlWidth)
                                    {
                                        pLbl.Width = c_ControlWidth;
                                        //Use autosize if it fits
                                    }
                                    else
                                    {
                                        pLbl.AutoSize = true;
                                    }

                                    //Create a new control to display the attributes
                                    pTxtBox = new TextBox();

                                    //Tag the control with the field it represents
                                    pTxtBox.Tag = (strfld).Trim();
                                    //Name the field with the field name
                                    pTxtBox.Name = "txtEdit" + strfld;
                                    //Locate the control on the display
                                    pTxtBox.Left = 0;

                                    pTxtBox.Width = c_ControlWidth;
                                    if (pDc.Type == esriFieldType.esriFieldTypeString)
                                    {
                                        //Make the box taller if it is a long field
                                        if (pDc.Length > 125)
                                        {
                                            pTxtBox.Multiline = true;
                                            pTxtBox.Height = pTxtBox.Height * 3;

                                        }

                                    }
                                    if (pDc.Length > 0)
                                    {
                                        pTxtBox.MaxLength = pDc.Length;
                                    }

                                    //Apply global font
                                    pTxtBox.Font = c_Fnt;

                                    //Group into panels to assist resizing
                                    Panel pPnl = new Panel();
                                    pPnl.BorderStyle = System.Windows.Forms.BorderStyle.None;

                                    pLbl.Top = 0;
                                    pTxtBox.Top = 5 + pLbl.Height;
                                    pPnl.Width = c_ControlWidth;
                                    pPnl.Margin = new Padding(0);
                                    pPnl.Padding = new Padding(0);

                                    pPnl.Top = 0;
                                    pPnl.Left = 0;
                                    pPnl.Height = pTxtBox.Height + pLbl.Height + 10;
                                    pPnl.Controls.Add(pLbl);
                                    pPnl.Controls.Add(pTxtBox);
                                    pTbPg.Controls.Add(pPnl);

                                }
                                else if (pDc.Type == esriFieldType.esriFieldTypeDate)
                                {
                                    //Create a lable for the field name
                                    pLbl = new Label();
                                    //Apply the field alias to the field name
                                    pLbl.Text = strAli;
                                    //Link the field to the name of the control
                                    pLbl.Name = "lblEdit" + strfld;
                                    //Add the control at the determined Location
                                    pLbl.Left = 0;

                                    //   pLbl.Top = pNextControlTop
                                    //Apply global font
                                    pLbl.Font = c_FntLbl;
                                    //Create a graphics object to messure the text
                                    g = pLbl.CreateGraphics();
                                    s = g.MeasureString(pLbl.Text, pLbl.Font);

                                    pLbl.Height = Convert.ToInt32(s.Height);
                                    //If the text is larger then the control, truncate the control
                                    if (s.Width >= c_ControlWidth)
                                    {
                                        pLbl.Width = c_ControlWidth;
                                        //Use autosize if it fits
                                    }
                                    else
                                    {
                                        pLbl.AutoSize = true;
                                    }
                                    //Determine the Location for the next control
                                    //   pNextControlTop = pLbl.Top + s.Height + intLabelCtrlSpace

                                    pDateTime = new DateTimePicker();
                                    pDateTime.Font = c_Fnt;
                                    //pDateTime.CustomFormat = "m/d/yyyy"
                                    pDateTime.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
                                    pDateTime.CustomFormat = "M-d-yy";
                                    // h:mm tt"
                                    pDateTime.ShowCheckBox = true;
                                    pDateTime.Tag = strfld;
                                    pDateTime.Name = "dtEdt" + strfld;
                                    pDateTime.Left = 0;
                                    //   pDateTime.Top = pNextControlTop
                                    pDateTime.Width = c_ControlWidth;

                                    //Determine the Location for the next control
                                    //pNextControlTop = pDateTime.Top + pDateTime.Height + intCtrlSpace
                                    Panel pPnl = new Panel();
                                    pPnl.BorderStyle = System.Windows.Forms.BorderStyle.None;

                                    pLbl.Top = 0;
                                    pDateTime.Top = 5 + pLbl.Height;
                                    pPnl.Width = c_ControlWidth;
                                    pPnl.Margin = new Padding(0);
                                    pPnl.Padding = new Padding(0);

                                    pPnl.Top = 0;
                                    pPnl.Left = 0;
                                    pPnl.Height = pDateTime.Height + pLbl.Height + 10;
                                    pPnl.Controls.Add(pLbl);
                                    pPnl.Controls.Add(pDateTime);
                                    pTbPg.Controls.Add(pPnl);

                                }
                                else if (pDc.Type == esriFieldType.esriFieldTypeRaster)
                                {
                                    //Create a lable for the field name
                                    pLbl = new Label();
                                    //Apply the field alias to the field name
                                    pLbl.Text = strAli;
                                    //Link the field to the name of the control
                                    pLbl.Name = "lblEdit" + strfld;
                                    //Add the control at the determined Location
                                    pLbl.Left = 0;
                                    pLbl.Top = 0;
                                    //Apply global font
                                    pLbl.Font = c_FntLbl;
                                    //Create a graphics object to messure the text
                                    g = pLbl.CreateGraphics();
                                    s = g.MeasureString(pLbl.Text, pLbl.Font);
                                    pLbl.Height = Convert.ToInt32(s.Height);
                                    //If the text is larger then the control, truncate the control
                                    if (s.Width >= c_ControlWidth)
                                    {
                                        pLbl.Width = 0;
                                        //Use autosize if it fits
                                    }
                                    else
                                    {
                                        pLbl.AutoSize = true;
                                    }
                                    //Determine the Location for the next control

                                    //Create a new control to display the attributes
                                    pTxtBox = new TextBox();
                                    //Disable the control
                                    //  pPic.ReadOnly = True
                                    //Tag the control with the field it represents
                                    pTxtBox.Tag = (strfld).Trim();
                                    //Name the field with the field name
                                    pTxtBox.Name = "txtEdit" + strfld;
                                    //Locate the control on the display
                                    pTxtBox.Left = 0;
                                    pTxtBox.Top = 0;
                                    pTxtBox.Width = c_ControlWidth - pTxtBox.Height;
                                    if (pDc.Type == esriFieldType.esriFieldTypeString)
                                    {
                                        //Make the box taller if it is a long field
                                        if (pDc.Length > 125)
                                        {
                                            pTxtBox.Multiline = true;
                                            pTxtBox.Height = pTxtBox.Height * 3;

                                        }

                                    }
                                    if (pDc.Length > 0)
                                    {
                                        pTxtBox.MaxLength = pDc.Length;
                                    }

                                    pTxtBox.BackgroundImageLayout = ImageLayout.Stretch;

                                    //Apply global font
                                    pTxtBox.Font = c_Fnt;

                                    pBtn = new System.Windows.Forms.Button();

                                    pBtn.Tag = (strfld).Trim();
                                    //Name the field with the field name
                                    pBtn.Name = "btnEdit" + strfld;
                                    //Locate the control on the display
                                    pBtn.Left = pTxtBox.Left + pTxtBox.Width + 5;
                                    pBtn.Top = 0;
                                    System.Drawing.Bitmap img = null;

                                    img = Properties.Resources.Open2;

                                    img.MakeTransparent(img.GetPixel(img.Width - 1, 1));

                                    pBtn.BackgroundImageLayout = ImageLayout.Center;
                                    pBtn.BackgroundImage = img;
                                    img = null;
                                    pBtn.Width = pTxtBox.Height;
                                    pBtn.Height = pTxtBox.Height;

                                    pBtn.Click += btnLoadImgClick;

                                    Panel pPnl = new Panel();
                                    pPnl.BorderStyle = System.Windows.Forms.BorderStyle.None;

                                    pLbl.Top = 0;
                                    pTxtBox.Top = 5 + pLbl.Height;
                                    pBtn.Top = pTxtBox.Top;
                                    pPnl.Width = c_ControlWidth;
                                    pPnl.Margin = new Padding(0);
                                    pPnl.Padding = new Padding(0);

                                    pPnl.Top = 0;
                                    pPnl.Left = 0;
                                    pPnl.Height = pTxtBox.Height + pLbl.Height + 10;
                                    pPnl.Controls.Add(pLbl);
                                    pPnl.Controls.Add(pTxtBox);
                                    pPnl.Controls.Add(pBtn);
                                    pTbPg.Controls.Add(pPnl);

                                }
                                else if (pDc.Type == esriFieldType.esriFieldTypeBlob)
                                {
                                    //Create a lable for the field name
                                    pLbl = new Label();
                                    //Apply the field alias to the field name
                                    pLbl.Text = strAli;
                                    //Link the field to the name of the control
                                    pLbl.Name = "lblEdit" + strfld;
                                    //Add the control at the determined Location
                                    pLbl.Left = 0;
                                    pLbl.Top = 0;
                                    //Apply global font
                                    pLbl.Font = c_FntLbl;
                                    //Create a graphics object to messure the text
                                    g = pLbl.CreateGraphics();
                                    s = g.MeasureString(pLbl.Text, pLbl.Font);
                                    pLbl.Height = Convert.ToInt32(s.Height);
                                    //If the text is larger then the control, truncate the control
                                    if (s.Width >= c_ControlWidth)
                                    {
                                        pLbl.Width = 0;
                                        //Use autosize if it fits
                                    }
                                    else
                                    {
                                        pLbl.AutoSize = true;
                                    }
                                    //Determine the Location for the next control

                                    //Create a new control to display the attributes
                                    pTxtBox = new TextBox();
                                    //Disable the control
                                    //  pPic.ReadOnly = True
                                    //Tag the control with the field it represents
                                    pTxtBox.Tag = (strfld).Trim();
                                    //Name the field with the field name
                                    pTxtBox.Name = "txtEdit" + strfld;
                                    //Locate the control on the display
                                    pTxtBox.Left = 0;
                                    pTxtBox.Top = 0;
                                    pTxtBox.Width = c_ControlWidth - pTxtBox.Height;
                                    if (pDc.Type == esriFieldType.esriFieldTypeString)
                                    {
                                        //Make the box taller if it is a long field
                                        if (pDc.Length > 125)
                                        {
                                            pTxtBox.Multiline = true;
                                            pTxtBox.Height = pTxtBox.Height * 3;

                                        }

                                    }
                                    if (pDc.Length > 0)
                                    {
                                        pTxtBox.MaxLength = pDc.Length;
                                    }

                                    pTxtBox.BackgroundImageLayout = ImageLayout.Stretch;

                                    //Apply global font
                                    pTxtBox.Font = c_Fnt;

                                    pBtn = new System.Windows.Forms.Button();

                                    pBtn.Tag = (strfld).Trim();
                                    //Name the field with the field name
                                    pBtn.Name = "btnEdit" + strfld;
                                    //Locate the control on the display
                                    pBtn.Left = pTxtBox.Left + pTxtBox.Width + 5;
                                    pBtn.Top = 0;
                                    System.Drawing.Bitmap img = null;

                                    img = Properties.Resources.Open2;

                                    img.MakeTransparent(img.GetPixel(img.Width - 1, 1));

                                    pBtn.BackgroundImageLayout = ImageLayout.Center;
                                    pBtn.BackgroundImage = img;
                                    img = null;
                                    pBtn.Width = pTxtBox.Height;
                                    pBtn.Height = pTxtBox.Height;

                                    pBtn.Click += btnLoadImgClick;

                                    Panel pPnl = new Panel();
                                    pPnl.BorderStyle = System.Windows.Forms.BorderStyle.None;

                                    pLbl.Top = 0;
                                    pTxtBox.Top = 5 + pLbl.Height;
                                    pBtn.Top = pTxtBox.Top;
                                    pPnl.Width = c_ControlWidth;
                                    pPnl.Margin = new Padding(0);
                                    pPnl.Padding = new Padding(0);

                                    pPnl.Top = 0;
                                    pPnl.Left = 0;
                                    pPnl.Height = pTxtBox.Height + pLbl.Height + 10;
                                    pPnl.Controls.Add(pLbl);
                                    pPnl.Controls.Add(pTxtBox);
                                    pPnl.Controls.Add(pBtn);
                                    pTbPg.Controls.Add(pPnl);

                                }
                            }
                            else
                            {
                                if (pDom is CodedValueDomain)
                                {
                                    ICodedValueDomain pCV = default(ICodedValueDomain);

                                    //Create a lable for the field name
                                    pLbl = new Label();
                                    //Apply the field alias to the field name
                                    pLbl.Text = strAli;
                                    //Link the field to the name of the control
                                    pLbl.Name = "lblEdit" + strfld;
                                    //Add the control at the determined Location
                                    pLbl.Left = 0;
                                    pLbl.Top = 0;
                                    //Apply global font
                                    pLbl.Font = c_FntLbl;
                                    //Create a graphics object to messure the text
                                    g = pLbl.CreateGraphics();
                                    s = g.MeasureString(pLbl.Text, pLbl.Font);
                                    pLbl.Height = Convert.ToInt32(s.Height);
                                    //If the text is larger then the control, truncate the control
                                    if (s.Width >= c_ControlWidth)
                                    {
                                        pLbl.Width = c_ControlWidth;
                                        //Use autosize if it fits
                                    }
                                    else
                                    {
                                        pLbl.AutoSize = true;
                                    }
                                    //Determine the Location for the next control
                                    //    pNextControlTop = pLbl.Top + s.Height + intLabelCtrlSpace

                                    pCV = (ICodedValueDomain)pDom;
                                    // pTbPg.Controls.Add(pLbl)

                                    if (pCV.CodeCount == 2)
                                    {
                                        CustomPanel pNewGpBox = new CustomPanel();
                                        pNewGpBox.Tag = strfld;
                                        pNewGpBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
                                        pNewGpBox.BackColor = Color.White;
                                        //  pNewGpBox.BorderColor = Pens.LightGray

                                        pNewGpBox.Width = c_ControlWidth;
                                        pNewGpBox.Top = 0;
                                        pNewGpBox.Left = 0;

                                        pRDButton = new RadioButton();
                                        pRDButton.Name = "Rdo1";
                                        string codeVal = "";
                                        string displayVal = "";
                                        Globals.DomainValuesAtIndex(0, (ICodedValueDomain)pCV, ref codeVal, ref displayVal);

                                        pRDButton.Tag = codeVal;
                                        pRDButton.Text = displayVal;
                                        pRDButton.Font = c_Fnt;
                                        //Dim pPf As SizeF = pRDButton.CreateGraphics.MeasureString(pRDButton.Text, pRDButton.Font)

                                        //'pRDButton.Height = pPf.Height
                                        //pRDButton.Width = pPf.Width + 25

                                        pRDButton.Left = pLeftPadding;

                                        pRDButton.AutoSize = true;
                                        pNewGpBox.Controls.Add(pRDButton);

                                        pNewGpBox.Height = pRDButton.Height + 12;
                                        pRDButton.Top = pNewGpBox.Height / 2 - pRDButton.Height / 2 - 2;

                                        pRDButton = new RadioButton();
                                        pRDButton.Font = c_Fnt;
                                        pRDButton.Name = "Rdo2";
                                        Globals.DomainValuesAtIndex(1, (ICodedValueDomain)pCV, ref codeVal, ref displayVal);

                                        pRDButton.Tag = codeVal;
                                        pRDButton.Text = displayVal;
                                        pRDButton.Left = pNewGpBox.Width / 2;
                                        //pPf = pRDButton.CreateGraphics.MeasureString(pRDButton.Text, pRDButton.Font)
                                        //pRDButton.Height = pPf.Height
                                        //pRDButton.Width = pPf.Width + 25

                                        pRDButton.AutoSize = true;
                                        pNewGpBox.Controls.Add(pRDButton);
                                        pRDButton.Top = pNewGpBox.Height / 2 - pRDButton.Height / 2 - 2;

                                        // pTbPg.Controls.Add(pNewGpBox)

                                        //  pNextControlTop = pNewGpBox.Top + pNewGpBox.Height + 7 + intLabelCtrlSpace

                                        Panel pPnl = new Panel();
                                        pPnl.BorderStyle = System.Windows.Forms.BorderStyle.None;

                                        pLbl.Top = 0;
                                        pNewGpBox.Top = 5 + pLbl.Height;

                                        pPnl.Width = c_ControlWidth;
                                        pPnl.Margin = new Padding(0);
                                        pPnl.Padding = new Padding(0);

                                        pPnl.Top = 0;
                                        pPnl.Left = 0;
                                        pPnl.Height = pNewGpBox.Height + pLbl.Height + 10;
                                        pPnl.Controls.Add(pLbl);
                                        pPnl.Controls.Add(pNewGpBox);

                                        pTbPg.Controls.Add(pPnl);

                                        pNewGpBox = null;
                                        //  pPf = Nothing

                                    }
                                    else
                                    {
                                        pCBox = new ComboBox();
                                        pCBox.Tag = strfld;
                                        pCBox.Name = "cboEdt" + strfld;
                                        pCBox.Left = 0;
                                        pCBox.Top = 0;
                                        pCBox.Width = c_ControlWidth;
                                        pCBox.Height = pCBox.Height + 5;
                                        pCBox.DropDownStyle = ComboBoxStyle.DropDownList;
                                        pCBox.Font = c_Fnt;
                                        pCBox.DataBindings.DefaultDataSourceUpdateMode = DataSourceUpdateMode.Never;

                                        pCBox.DataSource = Globals.DomainToList((IDomain)pCV);
                                        pCBox.DisplayMember = "getDisplay";
                                        pCBox.ValueMember = "getValue";
                                        // pCmdBox.MaxLength = pDc.Length

                                        Panel pPnl = new Panel();
                                        pPnl.BorderStyle = System.Windows.Forms.BorderStyle.None;

                                        pLbl.Top = 0;
                                        pCBox.Top = 5 + pLbl.Height;

                                        pPnl.Width = c_ControlWidth;
                                        pPnl.Margin = new Padding(0);
                                        pPnl.Padding = new Padding(0);

                                        pPnl.Top = 0;
                                        pPnl.Left = 0;
                                        pPnl.Height = pCBox.Height + pLbl.Height + 15;
                                        pPnl.Controls.Add(pLbl);
                                        pPnl.Controls.Add(pCBox);

                                        pTbPg.Controls.Add(pPnl);

                                        //   pTbPg.Controls.Add(pCBox)
                                        // MsgBox(pCBox.Items.Count)
                                        pCBox.Visible = true;

                                        string codeVal = "";
                                        string displayVal = "";
                                        Globals.DomainValuesAtIndex(0, (ICodedValueDomain)pCV, ref codeVal, ref displayVal);

                                        pCBox.Text = displayVal;

                                        //Try

                                        //pCBox.SelectedIndex = 0
                                        //Catch ex As Exception

                                        //End Try
                                        pCBox.Visible = true;
                                        pCBox.Refresh();

                                        //  pNextControlTop = pCBox.Top + pCBox.Height + 7 + intLabelCtrlSpace
                                    }

                                }
                                else if (pDom is RangeDomain)
                                {
                                    IRangeDomain pRV = default(IRangeDomain);
                                    //Create a lable for the field name
                                    pLbl = new Label();
                                    //Apply the field alias to the field name
                                    pLbl.Text = strAli;
                                    //Link the field to the name of the control
                                    pLbl.Name = "lblEdit" + strfld;
                                    //Add the control at the determined Location
                                    pLbl.Left = 0;
                                    pLbl.Top = 0;
                                    //Apply global font
                                    pLbl.Font = c_FntLbl;
                                    //Create a graphics object to messure the text
                                    g = pLbl.CreateGraphics();
                                    s = g.MeasureString(pLbl.Text, pLbl.Font);
                                    pLbl.Height = Convert.ToInt32(s.Height);
                                    //If the text is larger then the control, truncate the control
                                    if (s.Width >= c_ControlWidth)
                                    {
                                        pLbl.Width = c_ControlWidth;
                                        //Use autosize if it fits
                                    }
                                    else
                                    {
                                        pLbl.AutoSize = true;
                                    }
                                    //Determine the Location for the next control

                                    pRV = (IRangeDomain)pDom;
                                    pNumBox = new NumericUpDown();
                                    //    AddHandler pNumBox.MouseDown, AddressOf numericClickEvt_MouseDown

                                    if (pDc.Type == esriFieldType.esriFieldTypeInteger)
                                    {
                                        pNumBox.DecimalPlaces = 0;

                                    }
                                    else if (pDc.Type == esriFieldType.esriFieldTypeDouble)
                                    {
                                        pNumBox.DecimalPlaces = 2;
                                        //pDc.DataType.

                                    }
                                    else if (pDc.Type == esriFieldType.esriFieldTypeSingle)
                                    {
                                        pNumBox.DecimalPlaces = 1;
                                        //pDc.DataType.
                                    }
                                    else
                                    {
                                        pNumBox.DecimalPlaces = 2;
                                        //pDc.DataType.
                                    }

                                    pNumBox.Minimum = Convert.ToDecimal(pRV.MinValue.ToString());
                                    pNumBox.Maximum = Convert.ToDecimal(pRV.MaxValue.ToString());
                                    NumericUpDownAcceleration pf = new NumericUpDownAcceleration(3, Convert.ToInt32(Convert.ToDouble(pNumBox.Maximum - pNumBox.Minimum) * 0.02));

                                    pNumBox.Accelerations.Add(pf);

                                    pNumBox.Tag = strfld;
                                    pNumBox.Name = "numEdt" + strfld;
                                    pNumBox.Left = 0;
                                    pNumBox.BackColor = Color.White;
                                    pNumBox.Top = 0;
                                    pNumBox.Width = c_ControlWidth;
                                    pNumBox.Font = c_Fnt;

                                    Panel pPnl = new Panel();
                                    pPnl.BorderStyle = System.Windows.Forms.BorderStyle.None;

                                    pLbl.Top = 0;
                                    pNumBox.Top = 5 + pLbl.Height;

                                    pPnl.Width = c_ControlWidth;
                                    pPnl.Margin = new Padding(0);
                                    pPnl.Padding = new Padding(0);

                                    pPnl.Top = 0;
                                    pPnl.Left = 0;
                                    pPnl.Height = pNumBox.Height + pLbl.Height + 15;
                                    pPnl.Controls.Add(pLbl);
                                    pPnl.Controls.Add(pNumBox);

                                    pTbPg.Controls.Add(pPnl);

                                }

                            }

                        }
                        pLayerFields = null;
                        pFieldInfo = null;

                    }
                }
                //pDC

                if (pSubType.HasSubtype)
                {
                    SubtypeChange(pSubTypeDefValue, pSubType.SubtypeFieldName);

                }
                //cleanup
                pBtn = null;
                pDCs = null;
                pDc = null;

                pTbPg = null;

                pTxtBox = null;
                pLbl = null;
                pNumBox = null;

                pRDButton = null;

                pCBox = null;
                pDateTime = null;
                g = null;
                //s = null;
                s_tbCntlDisplay.ResumeLayout();
                s_tbCntlDisplay.Refresh();

            }
            catch (Exception ex)
            {
                MessageBox.Show("Error in the Costing Tools - CIPProjectWindow: AddControls" + Environment.NewLine + ex.Message);

            }
        }
Пример #32
0
        /// <summary>
        /// Instantiates a RemoveAccount object.
        /// </summary>
        /// <param name="domainInfo">The DomainInformation object for the account to be deleted.</param>
        public RemoveAccount(DomainInformation domainInfo)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            server.Text = domainInfo.Name;
            host.Text   = domainInfo.Host;
            user.Text   = domainInfo.MemberName;
            icon.Image  = Novell.Win32Util.Win32Window.IconToAlphaBitmap(SystemIcons.Question);

            removeAll.Enabled = domainInfo.Authenticated;

            int delta;
            int temp;

            // Calculate any needed expansion of label1 control.
            Graphics g = label1.CreateGraphics();

            try
            {
                SizeF textSize = g.MeasureString(label1.Text, label1.Font);
                delta = (int)Math.Ceiling(textSize.Width) - label1.Width;
            }
            finally
            {
                g.Dispose();
            }

            // Calculate any needed expansion of label2, label3, and label4 controls.
            SizeF label2Size;

            g = label2.CreateGraphics();
            try
            {
                label2Size = g.MeasureString(label2.Text, label2.Font);
            }
            finally
            {
                g.Dispose();
            }

            SizeF label3Size;

            g = label3.CreateGraphics();
            try
            {
                label3Size = g.MeasureString(label3.Text, label3.Font);
            }
            finally
            {
                g.Dispose();
            }

            SizeF label4Size;

            g = label4.CreateGraphics();
            try
            {
                label4Size = g.MeasureString(label4.Text, label4.Font);
            }
            finally
            {
                g.Dispose();
            }

            if (label2Size.Width > label3Size.Width &&
                label2Size.Width > label4Size.Width)
            {
                temp = (int)Math.Ceiling(label2Size.Width) - label2.Width;
            }
            else if (label3Size.Width > label2Size.Width &&
                     label3Size.Width > label4Size.Width)
            {
                temp = (int)Math.Ceiling(label3Size.Width) - label3.Width;
            }
            else
            {
                temp = (int)Math.Ceiling(label4Size.Width) - label4.Width;
            }

            if (temp > 0)
            {
                // Adjust the size of the labels and positions of the controls next to the labels.
                label2.Width = label3.Width = label4.Width += temp + 8;
                server.Left  = host.Left = user.Left = label2.Left + label2.Width + 8;
            }

            // We only need to keep track of the largest delta.
            if (temp > delta)
            {
                delta = temp;
            }

            // Calculate any needed expansion of server, host, and user controls.
            g = server.CreateGraphics();
            try
            {
                SizeF serverSize = g.MeasureString(server.Text, server.Font);
                g.Dispose();
                g = host.CreateGraphics();
                SizeF hostSize = g.MeasureString(host.Text, host.Font);
                g.Dispose();
                g = user.CreateGraphics();
                SizeF userSize = g.MeasureString(user.Text, user.Font);

                if ((serverSize.Width > hostSize.Width) &&
                    (serverSize.Width > userSize.Width))
                {
                    // The server name is the longest.
                    temp = (int)Math.Ceiling(serverSize.Width) - server.Width;
                }
                else if ((hostSize.Width > serverSize.Width) &&
                         (hostSize.Width > userSize.Width))
                {
                    // The host is the longest.
                    temp = (int)Math.Ceiling(hostSize.Width) - host.Width;
                }
                else
                {
                    // The username is the longest.
                    temp = (int)Math.Ceiling(userSize.Width) - user.Width;
                }
            }
            finally
            {
                g.Dispose();
            }

            if (temp > delta)
            {
                delta = temp;
            }

            // Calculate any needed expansion of removeAll control.
            g = removeAll.CreateGraphics();
            try
            {
                SizeF removeAllSize = g.MeasureString(removeAll.Text, removeAll.Font);
                temp = (int)Math.Ceiling(removeAllSize.Width) - removeAll.Width + 18;                 // +18 to account for the checkbox.
            }
            finally
            {
                g.Dispose();
            }

            if (temp > delta)
            {
                delta = temp;
            }

            // Adjust the width based on the largest delta.
            if (delta > 0)
            {
                this.Width += delta;
            }

            CenterToParent();
        }
Пример #33
0
        //Redraw all item to textbox.
        private void ReDraw()
        {
            //Clear all settings
            this.txtMain.Controls.Clear();
            InitDraw();

            int i;
            for (i = 0; i < Items.Count; i++)
            {
                Label myLabel = new Label();
                Font myFont = new Font("tahoma", 7);

                myLabel.Click += new EventHandler(myLabel_Click);
                myLabel.Text = this.Items[i].FileName;
                myLabel.Cursor = System.Windows.Forms.Cursors.Hand;
                myLabel.Font = myFont;
                myLabel.BorderStyle = BorderStyle.FixedSingle;
                SizeF textRange = myLabel.CreateGraphics().MeasureString(myLabel.Text, myFont);
                myLabel.Width = controlsPadding + 10 + (int)textRange.Width;
                myLabel.Height = controlsPadding + (int)textRange.Height;
                if ((maxControlsWidth + myLabel.Width + controlsPadding) > this.txtMain.Width)
                {
                    maxControlsHeight += (myLabel.Height + 2);
                    maxControlsWidth = controlsPadding;
                    this.Size = new Size(this.Size.Width, maxControlsHeight + 22);
                }
                myLabel.Location = new Point(maxControlsWidth, maxControlsHeight);
                maxControlsWidth += myLabel.Width + controlsPadding;
                this.txtMain.Controls.Add(myLabel);
            }
        }
Пример #34
0
        public static void FillCondition(string NameDevice,Label condition)
        {
            DriveInfo g = new DriveInfo(NameDevice);
            Graphics ShowCondition = condition.CreateGraphics();
            SolidBrush Fill;

            ShowCondition.SmoothingMode = SmoothingMode.HighQuality;

            ShowCondition.Clear(Color.Beige);

            int used = (int)(100 - ((g.TotalFreeSpace * 100) / g.TotalSize));

            if (used >= 90)
            {
                Fill = new SolidBrush(Color.Red);
            }
            else
            {
                Fill = new SolidBrush(Color.GreenYellow);
            }

            ShowCondition.FillRectangle(Fill, 0, 0, used, condition.Height);
        }
        public void OnClick(object obj, EventArgs click)
        {
            if (!(this.Checked)) {
                if (this.m_Connected) {
                    using (Synchronizer.Lock(this.m_ClassroomManager.Classroom.SyncRoot))
                        this.m_ClassroomManager.Classroom.Connected = false;
                    this.Text = Strings.ConnectToTCPServer;
                    this.m_Connected = false;

                }
                return;
            }

            if (this.m_ClassroomManager == null)
                return;

            using (Synchronizer.Lock(this.m_Model.ViewerState.SyncRoot)) {
                this.m_Model.ViewerState.ManualConnectionButtonName = this.Text;
            }
            if (this.m_Connected) {
                using (Synchronizer.Lock(this.m_ClassroomManager.Classroom.SyncRoot))
                    this.m_ClassroomManager.Classroom.Connected = false;
                this.Text = Strings.ConnectToTCPServer;
                this.m_Connected = false;
            }

            Label label = new Label();
            label.FlatStyle = FlatStyle.System;
            label.Font = Model.Viewer.ViewerStateModel.StringFont2;
            label.Text = Strings.ServerNameAddress;
            using (Graphics graphics = label.CreateGraphics())
                label.ClientSize = Size.Add(new Size(10, 0),
                    graphics.MeasureString(label.Text, label.Font).ToSize());
            label.Location = new Point(5, 5);

            Form form = new Form();
            form.Font = Model.Viewer.ViewerStateModel.FormFont;
            form.Text = Strings.ConnectToTCPServer;
            form.ClientSize = new Size(label.Width * 3, 2 * form.ClientSize.Height);
            form.FormBorderStyle = FormBorderStyle.FixedDialog;

            TextBox addressInput = new TextBox();
            addressInput.Font = Model.Viewer.ViewerStateModel.StringFont2;
            addressInput.Size = new Size(((int)(form.ClientSize.Width - (label.Width * 1.2))), this.Font.Height);
            addressInput.Location = new Point(((int)(label.Right * 1.1)), label.Top);

            using (Synchronizer.Lock(this.m_Model.ViewerState.SyncRoot)) {
                if (this.m_Model.ViewerState.TCPaddress != "" && this.m_Model.ViewerState.TCPaddress.Length != 0) {
                    string addr = this.m_Model.ViewerState.TCPaddress;
                    addressInput.Text = addr;
                }
            }

            Label label2 = new Label();
            label2.FlatStyle = FlatStyle.System;
            label2.Font = Model.Viewer.ViewerStateModel.StringFont2;
            label2.Text = Strings.Port;
            using (Graphics graphics = label.CreateGraphics())
                label2.ClientSize = Size.Add(new Size(10, 0),
                    graphics.MeasureString(label2.Text, label2.Font).ToSize());
            label2.Location = new Point(5, Math.Max(addressInput.Bottom, label.Bottom) + 10);

            TextBox portInput = new TextBox();
            portInput.Font = Model.Viewer.ViewerStateModel.StringFont2;
            portInput.Size = new Size((4 / 3) * sizeConst, sizeConst / 2);
            portInput.Location = new Point(addressInput.Left, label2.Top);
            portInput.Text = TCPServer.DefaultPort.ToString();

            Button okay = new Button();
            okay.FlatStyle = FlatStyle.System;
            okay.Font = Model.Viewer.ViewerStateModel.StringFont;
            okay.Text = Strings.OK;
            okay.Width = (addressInput.Right - label.Left) / 2 - 5;
            okay.Location = new Point(label.Left, Math.Max(portInput.Bottom, label2.Bottom) + 10);

            Button cancel = new Button();
            cancel.FlatStyle = FlatStyle.System;
            cancel.Font = Model.Viewer.ViewerStateModel.StringFont;
            cancel.Text = Strings.Cancel;
            cancel.Width = okay.Width;
            cancel.Location = new Point(okay.Right + 10, okay.Top);

            EventHandler connect = delegate(object source, EventArgs args) {

                    string address = addressInput.Text;

                using (Synchronizer.Lock(this.m_Model.ViewerState.SyncRoot)) {
                    this.m_Model.ViewerState.TCPaddress = address;
                }
                try {
                    IPHostEntry entry = Dns.GetHostEntry(address);
                    address = entry.AddressList[0].ToString();
                    int port = 0;
                    if (!Int32.TryParse(portInput.Text, out port))
                        port = TCPServer.DefaultPort;
                    IPEndPoint ep = new IPEndPoint(IPAddress.Parse(address), port);
                    this.m_ClassroomManager.RemoteServerEndPoint = ep;
                    using (Synchronizer.Lock(m_ClassroomManager.Classroom.SyncRoot))
                        m_ClassroomManager.Classroom.Connected = true;
                    this.m_Connected = true;
                    form.Dispose();
                }
                catch (Exception e) {
                    MessageBox.Show(
                        string.Format("Classroom Presenter was unable to connect to\n\n"
                            + "\t\"{0}\"\n\nfor the following reason:\n\n{1}",
                            address, e.Message),
                        "Connection Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    this.m_Connected = false;
                }
            };

            /*host.KeyPress += delegate(object source, KeyPressEventArgs args) {
                if (args.KeyChar == '\r')
                    connect(source, EventArgs.Empty);
                }*/

            okay.Click += connect;

            cancel.Click += delegate(object source, EventArgs args) {
                this.m_Connected = false;
                this.Checked = false;
                form.Dispose();
            };

            form.ClientSize = new Size(form.ClientSize.Width, Math.Max(okay.Bottom, cancel.Bottom) + 5);

            form.Controls.Add(label);
            form.Controls.Add(addressInput);
            form.Controls.Add(label2);
            form.Controls.Add(portInput);
            form.Controls.Add(okay);
            form.Controls.Add(cancel);

            DialogResult dr = form.ShowDialog();
            //this.GetMainMenu() != null ? this.GetMainMenu().GetForm() : null);

            /*else {
                m_ClassoomManager.ClientDisconnect();
                this.Text = "Connect to &TCP Server...";
                m_Connected = false;
                }*/

            /////////
        }
Пример #36
0
		internal System.Windows.Forms.DialogResult ShowDialog(String message, String caption, String description, SWDialogBox.MessageBoxButton button, SWDialogBox.MessageBoxIcon icon)
		{
			try
			{
				String iconKey = null;
				System.Resources.ResourceManager rm = new System.Resources.ResourceManager("SWDialogBox.SWDialogBox", this.GetType().Assembly);

				//根据当前的消息编号得到其对应的消息类型(设置消息框图标类型)
				switch((icon & (SWDialogBox.MessageBoxIcon)ICONMASKWORD))
				{
					case SWDialogBox.MessageBoxIcon.Critical:
						iconKey = "ICON-Critical";
						break;
					case SWDialogBox.MessageBoxIcon.Question:
						iconKey = "ICON-Question";
						break;
					case SWDialogBox.MessageBoxIcon.Exclamation:
						iconKey = "ICON-Exclamation";
						break;
					case SWDialogBox.MessageBoxIcon.Information:
						iconKey = "ICON-Information";
						break;
				}

				//装载消息框指示图标
				if(iconKey != null && iconKey != String.Empty)
					this.MessageIcon.Image = ((System.Drawing.Icon)rm.GetObject(iconKey)).ToBitmap();

				//装载消息框窗体图标
//				if(this.Icon != null)
//					this.Icon = (System.Drawing.Icon)rm.GetObject("ICON-App");

				//设置消息框中各个信息文本
				this.Text = caption;
				lblMessage.Text = message;
				txtDescription.Text = description;

				//得到消息文本框的Graphics对象
				Graphics g = lblMessage.CreateGraphics();

				//得到将显示的消息文本的显示区域/大小
				SizeF messageSize = new SizeF();
				messageSize = g.MeasureString(lblMessage.Text, lblMessage.Font, lblMessage.Width);

				//设置消息文本框的高度
				lblMessage.Height = (Int32)messageSize.Height;
				//设置按钮的位置
				btnDetail.Top = lblMessage.Top + lblMessage.Height + 32;
				//设置消息框窗体的高度
				this.ClientSize = new System.Drawing.Size(this.ClientSize.Width,
														  btnDetail.Top + btnDetail.Height + 16);

				//创建消息框的按钮并排版消息框窗体界面
				this.CreateButton(button);

				//打开模式对话框
				return this.ShowDialog();
			}
			catch
			{
				throw;
			}
		}
Пример #37
0
        /// <summary>
        /// Resize Controls
        /// </summary>
        private void resizeControl()
        {
            float  width  = 0;
            float  height = 0;
            double lines  = 1;
            SizeF  size   = new SizeF(0, 0);

            Graphics g = message.CreateGraphics();

            // Split the string at the newline boundaries.
            Regex regex = new Regex("[\n]+");

            foreach (string s in regex.Split(message.Text))
            {
                // Calculate the size for each string.
                size    = g.MeasureString(s, message.Font);
                width   = Math.Max((size.Width / maxWidth) > 1 ? maxWidth : size.Width, width);
                lines   = Math.Ceiling(size.Width / width);
                height += (float)lines * size.Height;
            }

            g.Dispose();

            int index        = 0;
            int newlineCount = 0;

            // Count how many blank lines we have.
            while ((index = message.Text.IndexOf("\n", index)) != -1)
            {
                while (message.Text[++index] == '\n')
                {
                    newlineCount++;
                    if (index > message.Text.Length - 1)
                    {
                        break;
                    }
                }
            }

            // Adjust the height to include the blank lines.
            height += (size.Height * newlineCount) + (float)(2 * lines);

            message.Size = new Size((int)Math.Ceiling(width), (int)Math.Ceiling(height));

            if (details.Visible)
            {
                resizeButton(details);
            }

            // Calculate the size of the message box.
            int msgWidth = message.Width + message.Left + 4;

            this.Width = Math.Max(msgWidth, details.Visible ? 2 * (details.Width + 14) + ok.Width : 0);

            // Place the buttons.
            ok.Top = message.Bottom + 12;
            if (cancel.Visible)
            {
                ok.Left     = (ClientRectangle.Width / 2) - (ok.Width + 4);
                cancel.Left = ok.Right + 4;
                cancel.Top  = ok.Top;
            }
            else
            {
                ok.Left = (ClientRectangle.Width - ok.Width) / 2;
            }

            if (yes.Visible)
            {
                yes.Left    = (ClientRectangle.Width / 2) - (yes.Width + 4);
                no.Left     = yes.Right + 4;
                yes.Top     = no.Top = ok.Top;
                this.Height = ok.Bottom + (this.Height - ClientRectangle.Height) + 12;
            }

            details.Top      = ok.Top;
            details.Left     = ClientRectangle.Right - (details.Width + 8);
            detailsBox.Top   = ok.Bottom + 8;
            detailsBox.Width = ClientRectangle.Right - (detailsBox.Left * 2);
        }
Пример #38
0
 private void FitToWidth(Label ctrl, float maxAdjust)
 {
     Font retFont = (Font)ctrl.Font.Clone();
     float minSize = retFont.Size - maxAdjust;
     using (Graphics graphics = ctrl.CreateGraphics())
     {
         float textWidth = graphics.MeasureString(ctrl.Text, retFont).Width;
         while (textWidth > (float)ctrl.Width && retFont.Size > minSize)
         {
             retFont = new Font(retFont.Name, (retFont.Size - 0.1F));
             textWidth = graphics.MeasureString(ctrl.Text, retFont).Width;
         }
         ctrl.Font = retFont;
     }
 }
Пример #39
0
        private Label createLabel(string text)
        {
            Label lbl = new Label();
            lbl.Text = text;
            lbl.Width = (int)lbl.CreateGraphics().MeasureString(text, this.pnlQGroup.Font).Width + 6;
            System.Windows.Forms.Padding margin = lbl.Margin;
            margin.Top = 3;
            margin.Right = 0;
            lbl.Margin = margin;

            return lbl;
        }
Пример #40
0
        public override void LoadForm()
        {
            this.SuspendForm();
            NotificationInitialize();
            if (hunting_place == null) return;
            this.cityLabel.Text = hunting_place.city;
            this.huntingPlaceName.Text = MainForm.ToTitle(hunting_place.name);
            this.levelLabel.Text = hunting_place.level < 0 ? "--" : hunting_place.level.ToString();

            if (hunting_place.directions.Count == 0) {
                guideButton.Visible = false;
            }

            int y;
            ToolTip tooltip = new ToolTip();
            tooltip.AutoPopDelay = 60000;
            tooltip.InitialDelay = 500;
            tooltip.ReshowDelay = 0;
            tooltip.ShowAlways = true;
            tooltip.UseFading = true;

            if (this.hunting_place.coordinates != null && this.hunting_place.coordinates.Count > 0) {
                int count = 1;
                foreach (Coordinate coordinate in this.hunting_place.coordinates) {
                    Label label = new Label();
                    label.ForeColor = MainForm.label_text_color;
                    label.BackColor = Color.Transparent;
                    label.Name = (count - 1).ToString();
                    label.Font = LootDropForm.loot_font;
                    label.Text = count.ToString();
                    label.BorderStyle = BorderStyle.FixedSingle;
                    label.Size = new Size(1, 1);
                    label.AutoSize = true;
                    label.Location = new Point(mapBox.Location.X + (count - 1) * 25, mapBox.Location.Y + mapBox.Size.Height + 5);
                    label.Click += label_Click;
                    this.Controls.Add(label);
                    count++;
                }
                targetCoordinate = this.hunting_place.coordinates[0];

            } else {
                targetCoordinate = new Coordinate();
            }

            if (hunting_place.requirements != null && hunting_place.requirements.Count > 0) {
                int count = 0;
                y = 3;
                foreach (Requirements requirement in hunting_place.requirements) {
                    Label label = new Label();
                    label.ForeColor = Color.Firebrick;
                    label.BackColor = Color.Transparent;
                    label.Font = requirement_font;
                    label.Location = new Point(3, requirementLabel.Location.Y + requirementLabel.Size.Height + y);
                    label.AutoSize = true;
                    label.MaximumSize = new Size(170, 0);
                    label.Text = "- " + requirement.notes;
                    label.Name = requirement.quest.name.ToString();
                    label.Click += openQuest;
                    using (Graphics graphics = label.CreateGraphics()) {
                        y += (int)(Math.Ceiling(graphics.MeasureString(label.Text, label.Font).Width / 170.0)) * 14;
                    }
                    this.Controls.Add(label);
                    count++;
                }
            } else {
                this.requirementLabel.Hide();
            }

            baseY = this.creatureLabel.Location.Y + this.creatureLabel.Height + 5;

            //y = MainForm.DisplayCreatureList(this.Controls, creatures, 10, base_y, this.Size.Width, 4, null, 0.8f);

            Font f = MainForm.fontList[0];
            for (int i = 0; i < MainForm.fontList.Count; i++) {
                Font font = MainForm.fontList[i];
                int width = TextRenderer.MeasureText(this.huntingPlaceName.Text, font).Width;
                if (width < this.huntingPlaceName.Size.Width) {
                    f = font;
                } else {
                    break;
                }
            }

            Bitmap bitmap = new Bitmap(experienceStarBox.Size.Width, experienceStarBox.Size.Height);
            Graphics gr = Graphics.FromImage(bitmap);
            for (int i = 0; i < (this.hunting_place.exp_quality < 0 ? 5 : Math.Min(this.hunting_place.exp_quality, 5)); i++) {
                string huntQuality = this.hunting_place.exp_quality < 0 ? "unknown" : (this.hunting_place.exp_quality - 1).ToString();
                gr.DrawImage(StyleManager.GetImage(String.Format("star{0}.png", huntQuality)), new Rectangle(i * experienceStarBox.Size.Width / 5, 0, experienceStarBox.Size.Width / 5, experienceStarBox.Size.Width / 5));
            }
            experienceStarBox.Image = bitmap;

            bitmap = new Bitmap(lootStarBox.Size.Width, lootStarBox.Size.Height);
            gr = Graphics.FromImage(bitmap);
            for (int i = 0; i < (this.hunting_place.loot_quality < 0 ? 5 : Math.Min(this.hunting_place.loot_quality, 5)); i++) {
                string huntQuality = this.hunting_place.loot_quality < 0 ? "unknown" : (this.hunting_place.loot_quality - 1).ToString();
                gr.DrawImage(StyleManager.GetImage(String.Format("star{0}.png", huntQuality)), new Rectangle(i * lootStarBox.Size.Width / 5, 0, lootStarBox.Size.Width / 5, lootStarBox.Size.Width / 5));
            }
            lootStarBox.Image = bitmap;

            this.huntingPlaceName.Font = f;
            this.refreshCreatures();
            UpdateMap();

            mapBox.Click -= c_Click;

            this.mapUpLevel.Image = StyleManager.GetImage("mapup.png");
            this.mapUpLevel.Click -= c_Click;
            this.mapUpLevel.Click += mapUpLevel_Click;
            this.mapDownLevel.Image = StyleManager.GetImage("mapdown.png");
            this.mapDownLevel.Click -= c_Click;
            this.mapDownLevel.Click += mapDownLevel_Click;
            base.NotificationFinalize();
            this.ResumeForm();
        }
Пример #41
0
		void ChooseLabelFont(Label label) {
			if ((bool?)label.Tag != true)
				return;

			using (var g = label.CreateGraphics()) {
				int sizeRatio = (int)g.MeasureString(label.Text, font).Width / GameArea.ClientSize.Width;
				if (sizeRatio >= 2)
					label.Font = extraSmallFont;
				else if (sizeRatio >= 1)
					label.Font = smallFont;
				else
					label.Font = font;
			}
		}