powered by simpleCommunicator - 2.0.51     © 2025 Programmizd 02
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / Спрятать элементы формы
19 сообщений из 19, страница 1 из 1
Спрятать элементы формы
    #37399794
izoldov-roskini
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Есть форма. На форме 3 кнопки. Как можно по имени кнопки, ее напрмер скрыть? Должно получится что-то типа этого (очень абстрактно):
Код: plaintext
1.
form["button1"].Visible = false;
Поясню: список элементов в форме лежит в БД, хочется прятать те элементы, у которых признак видимости в БД будет false.
...
Рейтинг: 0 / 0
Спрятать элементы формы
    #37399860
Фотография Deft
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
izoldov-roskini,

form.Controls("Button1").Visible=False
...
Рейтинг: 0 / 0
Спрятать элементы формы
    #37399903
izoldov-roskini
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
уточняю, нужно сделать элемент невидимым в не зависимости от того на каком контейнере он находится. То что Вы написали работает только если педалька лежит на форме, а вот если она лежит на панели, которая лежит на форме - то ничего не работает. Может есть способ найти элемент по имени на форме?
...
Рейтинг: 0 / 0
Спрятать элементы формы
    #37399949
Syrex
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Может пробовать проверять в Event контрола?!
...
Рейтинг: 0 / 0
Спрятать элементы формы
    #37400100
Фотография pf
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
izoldov-roskini,

Вот функция, которая заполняет все подписи на форме (для многоязычности). Написана грубовато, некоторые части можно заменить на рекурсивный вызов, но идея вам подойдет, я думаю :

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
245.
246.
247.
248.
249.
250.
251.
252.
253.
254.
255.
256.
257.
258.
259.
260.
261.
262.
263.
264.
265.
266.
267.
268.
269.
270.
271.
272.
273.
274.
275.
276.
277.
278.
279.
280.
281.
282.
283.
284.
285.
286.
287.
288.
289.
290.
291.
292.
293.
294.
295.
296.
297.
298.
299.
300.
301.
302.
303.
304.
305.
306.
307.
308.
309.
310.
311.
312.
313.
314.
315.
316.
317.
318.
319.
320.
321.
322.
323.
324.
325.
326.
327.
328.
329.
330.
331.
332.
333.
334.
335.
336.
337.
338.
339.
340.
341.
342.
343.
344.
345.
346.
347.
348.
349.
350.
351.
352.
353.
354.
355.
356.
357.
358.
359.
360.
361.
362.
363.
364.
365.
366.
367.
368.
369.
370.
371.
372.
373.
374.
375.
376.
377.
378.
379.
380.
381.
382.
383.
384.
385.
386.
387.
388.
389.
390.
391.
392.
393.
394.
395.
396.
397.
398.
399.
400.
401.
402.
403.
404.
405.
406.
407.
408.
409.
410.
411.
412.
413.
414.
415.
416.
417.
418.
419.
420.
421.
422.
423.
424.
425.
426.
427.
428.
429.
430.
431.
432.
433.
434.
435.
436.
437.
438.
439.
440.
441.
442.
443.
444.
445.
446.
447.
448.
449.
450.
451.
452.
453.
454.
455.
456.
457.
458.
459.
460.
461.
462.
463.
464.
465.
466.
467.
468.
469.
470.
471.
472.
473.
474.
475.
476.
477.
478.
479.
480.
481.
482.
483.
484.
485.
486.
487.
488.
489.
490.
491.
492.
493.
494.
495.
496.
497.
498.
499.
500.
501.
502.
503.
504.
505.
506.
507.
508.
509.
510.
511.
512.
513.
514.
515.
516.
517.
518.
519.
520.
521.
522.
523.
524.
525.
526.
527.
528.
529.
530.
531.
532.
533.
534.
535.
536.
537.
538.
539.
540.
541.
542.
543.
544.
545.
546.
547.
548.
549.
550.
551.
552.
553.
554.
555.
556.
557.
558.
559.
560.
561.
562.
563.
564.
565.
566.
567.
568.
569.
570.
571.
572.
573.
574.
575.
576.
577.
578.
579.
580.
581.
582.
583.
584.
585.
586.
587.
588.
589.
590.
591.
592.
593.
594.
595.
596.
597.
598.
599.
600.
601.
602.
603.
604.
605.
606.
607.
608.
609.
610.
611.
612.
613.
614.
615.
616.
617.
618.
619.
620.
621.
622.
623.
624.
625.
626.
627.
public void f_FillDescriptions(System.Windows.Forms.Form frmForm, SalaryProMain frmMain)
        {
            // Форма
            string strText = f_FillLanDescriptions(frmForm.Name, frmMain.tDesc);
            if (strText != "")
            {
                frmForm.Text = strText;
            }            
            // Контролы формы
            foreach (System.Windows.Forms.Control ctrl in frmForm.Controls)
            {
                switch (ctrl.GetType().Name)
                {
                    case "MenuStrip":
                        System.Windows.Forms.ToolStripMenuItem mnuItem;
                        for (int i = 0; i < frmForm.MainMenuStrip.Items.Count; i++)
                        {
                            mnuItem = (System.Windows.Forms.ToolStripMenuItem)frmForm.MainMenuStrip.Items[i];
                            strText = f_FillLanDescriptions(mnuItem.Name, frmMain.tDesc);
                            if (strText != "")
                            {
                                mnuItem.Text = strText;
                            }
                            f_FillMnuSubItems(mnuItem, frmMain);
                        }
                        break;

                    case "DataGridView":
                        System.Windows.Forms.DataGridView dgw;
                        System.Windows.Forms.DataGridViewColumn _column;
                        dgw = (System.Windows.Forms.DataGridView)ctrl;
                        for (int b = 0; b < dgw.Columns.Count; b++)
                        {
                            _column = dgw.Columns[b];
                            strText = f_FillLanDescriptions(_column.Name, frmMain.tDesc);
                            if (strText != "")
                            {
                                _column.HeaderText = strText;
                            }
                        }                            
                        break;

                    case "Label":
                        strText = f_FillLanDescriptions(ctrl.Name, frmMain.tDesc);
                        if (strText != "")
                        {
                            ctrl.Text = strText;
                        }
                        break;

                    case "Button":
                        strText = f_FillLanDescriptions(ctrl.Name, frmMain.tDesc);
                        if (strText != "")
                        {
                            ctrl.Text = strText;
                        }
                        break;

                    case "TabControl":
                        System.Windows.Forms.TabPage _page;
                        System.Windows.Forms.TabControl _tabcontrol = (System.Windows.Forms.TabControl)ctrl;
                        for (int c = 0; c < _tabcontrol.TabCount; c++)
                        {
                            _page = _tabcontrol.TabPages[c];
                            strText = f_FillLanDescriptions(_page.Name, frmMain.tDesc);
                            if (strText != "")
                            {
                                _page.Text = strText;
                            }
                            foreach (System.Windows.Forms.Control ctrltabpage in _page.Controls)
                            {
                                switch (ctrltabpage.GetType().Name)
                                {
                                    case "MenuStrip":
                                        System.Windows.Forms.ToolStripMenuItem mnuItm;
                                        for (int i = 0; i < frmForm.MainMenuStrip.Items.Count; i++)
                                        {
                                            mnuItm = (System.Windows.Forms.ToolStripMenuItem)frmForm.MainMenuStrip.Items[i];
                                            strText = f_FillLanDescriptions(mnuItm.Name, frmMain.tDesc);
                                            if (strText != "")
                                            {
                                                mnuItm.Text = strText;
                                            }
                                            f_FillMnuSubItems(mnuItm, frmMain);
                                        }
                                        break;

                                    case "DataGridView":
                                        System.Windows.Forms.DataGridView dgw1;
                                        System.Windows.Forms.DataGridViewColumn _column1;
                                        dgw1 = (System.Windows.Forms.DataGridView)ctrltabpage;
                                        for (int b = 0; b < dgw1.Columns.Count; b++)
                                        {
                                            _column1 = dgw1.Columns[b];
                                            strText = f_FillLanDescriptions(_column1.Name, frmMain.tDesc);
                                            if (strText != "")
                                            {
                                                _column1.HeaderText = strText;
                                            }
                                        }
                                        break;

                                    case "Label":
                                        strText = f_FillLanDescriptions(ctrltabpage.Name, frmMain.tDesc);
                                        if (strText != "")
                                        {
                                            ctrltabpage.Text = strText;
                                        }
                                        break;

                                    case "Button":
                                        strText = f_FillLanDescriptions(ctrltabpage.Name, frmMain.tDesc);
                                        if (strText != "")
                                        {
                                            ctrltabpage.Text = strText;
                                        }
                                        break;

                                    case "GroupBox":
                                        strText = f_FillLanDescriptions(ctrltabpage.Name, frmMain.tDesc);
                                        if (strText != "")
                                        {
                                            ctrltabpage.Text = strText;
                                        }
                                        System.Windows.Forms.GroupBox _groupbox = (System.Windows.Forms.GroupBox)ctrltabpage;
                                        for (int f = 0; f < _groupbox.Controls.Count; f++)
                                        {
                                            System.Windows.Forms.Control _grpctrl = _groupbox.Controls[f];
                                            switch (_grpctrl.GetType().Name)
                                            {
                                                case "MenuStrip":
                                                    System.Windows.Forms.ToolStripMenuItem mnuItm1;
                                                    for (int i = 0; i < frmForm.MainMenuStrip.Items.Count; i++)
                                                    {
                                                        mnuItm1 = (System.Windows.Forms.ToolStripMenuItem)frmForm.MainMenuStrip.Items[i];
                                                        strText = f_FillLanDescriptions(mnuItm1.Name, frmMain.tDesc);
                                                        if (strText != "")
                                                        {
                                                            mnuItm1.Text = strText;
                                                        }
                                                        f_FillMnuSubItems(mnuItm1, frmMain);
                                                    }
                                                    break;

                                                case "DataGridView":
                                                    System.Windows.Forms.DataGridView dgw2;
                                                    System.Windows.Forms.DataGridViewColumn _column2;
                                                    dgw2 = (System.Windows.Forms.DataGridView)_grpctrl;
                                                    for (int b = 0; b < dgw2.Columns.Count; b++)
                                                    {
                                                        _column2 = dgw2.Columns[b];
                                                        strText = f_FillLanDescriptions(_column2.Name, frmMain.tDesc);
                                                        if (strText != "")
                                                        {
                                                            _column2.HeaderText = strText;
                                                        }
                                                    }
                                                    break;

                                                case "Label":
                                                    strText = f_FillLanDescriptions(_grpctrl.Name, frmMain.tDesc);
                                                    if (strText != "")
                                                    {
                                                        _grpctrl.Text = strText;
                                                    }
                                                    break;

                                                case "Button":
                                                    strText = f_FillLanDescriptions(_grpctrl.Name, frmMain.tDesc);
                                                    if (strText != "")
                                                    {
                                                        _grpctrl.Text = strText;
                                                    }
                                                    break;

                                                case "GroupBox":
                                                    strText = f_FillLanDescriptions(ctrl.Name, frmMain.tDesc);
                                                    if (strText != "")
                                                    {
                                                        ctrl.Text = strText;
                                                    }
                                                    break;
                                            }
                                        }
                                        break;
                                }
                            }
                        }
                        break;

                    case "Panel":
                        System.Windows.Forms.Panel _panel = (System.Windows.Forms.Panel)ctrl;
                        for (int d = 0; d < _panel.Controls.Count;d++ )                            
                        {
                            System.Windows.Forms.Control ctrlp = _panel.Controls[d];
                            switch (ctrlp.GetType().Name)
                            {
                                case "MenuStrip":
                                    System.Windows.Forms.ToolStripMenuItem mnuItm;
                                    for (int i = 0; i < frmForm.MainMenuStrip.Items.Count; i++)
                                    {
                                        mnuItm = (System.Windows.Forms.ToolStripMenuItem)frmForm.MainMenuStrip.Items[i];
                                        strText = f_FillLanDescriptions(mnuItm.Name, frmMain.tDesc);
                                        if (strText != "")
                                        {
                                            mnuItm.Text = strText;
                                        }
                                        f_FillMnuSubItems(mnuItm, frmMain);
                                    }
                                    break;
                                    
                                case "DataGridView":
                                    System.Windows.Forms.DataGridView dgw1;
                                    System.Windows.Forms.DataGridViewColumn _column1;
                                    dgw1 = (System.Windows.Forms.DataGridView)ctrlp;
                                    for (int b = 0; b < dgw1.Columns.Count; b++)
                                    {
                                        _column1 = dgw1.Columns[b];
                                        strText = f_FillLanDescriptions(_column1.Name, frmMain.tDesc);
                                        if (strText != "")
                                        {
                                            _column1.HeaderText = strText;
                                        }
                                    }
                                    break;
                                    
                                case "Label":
                                    strText = f_FillLanDescriptions(ctrlp.Name, frmMain.tDesc);
                                    if (strText != "")
                                    {
                                        ctrlp.Text = strText;
                                    }
                                    break;

                                case "Button":
                                    strText = f_FillLanDescriptions(ctrlp.Name, frmMain.tDesc);
                                    if (strText != "")
                                    {
                                        ctrlp.Text = strText;
                                    }
                                    break;

                                case "GroupBox":
                                    strText = f_FillLanDescriptions(ctrlp.Name, frmMain.tDesc);
                                    if (strText != "")
                                    {
                                        ctrlp.Text = strText;
                                    }
                                    System.Windows.Forms.GroupBox _groupbox = (System.Windows.Forms.GroupBox)ctrlp;
                                    for (int f = 0; f < _groupbox.Controls.Count; f++)
                                    {
                                        System.Windows.Forms.Control _grpctrl = _groupbox.Controls[f];
                                        switch (_grpctrl.GetType().Name)
                                        {
                                            case "MenuStrip":
                                                System.Windows.Forms.ToolStripMenuItem mnuItm1;
                                                for (int i = 0; i < frmForm.MainMenuStrip.Items.Count; i++)
                                                {
                                                    mnuItm1 = (System.Windows.Forms.ToolStripMenuItem)frmForm.MainMenuStrip.Items[i];
                                                    strText = f_FillLanDescriptions(mnuItm1.Name, frmMain.tDesc);
                                                    if (strText != "")
                                                    {
                                                        mnuItm1.Text = strText;
                                                    }
                                                    f_FillMnuSubItems(mnuItm1, frmMain);
                                                }
                                                break;

                                            case "DataGridView":
                                                System.Windows.Forms.DataGridView dgw2;
                                                System.Windows.Forms.DataGridViewColumn _column2;
                                                dgw2 = (System.Windows.Forms.DataGridView)_grpctrl;
                                                for (int b = 0; b < dgw2.Columns.Count; b++)
                                                {
                                                    _column2 = dgw2.Columns[b];
                                                    strText = f_FillLanDescriptions(_column2.Name, frmMain.tDesc);
                                                    if (strText != "")
                                                    {
                                                        _column2.HeaderText = strText;
                                                    }
                                                }
                                                break;

                                            case "Label":
                                                strText = f_FillLanDescriptions(_grpctrl.Name, frmMain.tDesc);
                                                if (strText != "")
                                                {
                                                    _grpctrl.Text = strText;
                                                }
                                                break;

                                            case "Button":
                                                strText = f_FillLanDescriptions(_grpctrl.Name, frmMain.tDesc);
                                                if (strText != "")
                                                {
                                                    _grpctrl.Text = strText;
                                                }
                                                break;

                                            case "GroupBox":
                                                strText = f_FillLanDescriptions(_grpctrl.Name, frmMain.tDesc);
                                                if (strText != "")
                                                {
                                                    _grpctrl.Text = strText;
                                                }
                                                break;
                                        }
                                    }
                                    break;
                                }
                            }
                        break;

                    case "SplitContainer":
                        System.Windows.Forms.SplitContainer _splcontainer = (System.Windows.Forms.SplitContainer)ctrl;
                        for (int e = 0; e < _splcontainer.Panel1.Controls.Count; e++)
                        {
                            System.Windows.Forms.Control splctrl = _splcontainer.Panel1.Controls[e];
                            switch (splctrl.GetType().Name)
                            {
                                case "MenuStrip":
                                    System.Windows.Forms.ToolStripMenuItem mnuItm;
                                    for (int i = 0; i < frmForm.MainMenuStrip.Items.Count; i++)
                                    {
                                        mnuItm = (System.Windows.Forms.ToolStripMenuItem)frmForm.MainMenuStrip.Items[i];
                                        strText = f_FillLanDescriptions(mnuItm.Name, frmMain.tDesc);
                                        if (strText != "")
                                        {
                                            mnuItm.Text = strText;
                                        }
                                        f_FillMnuSubItems(mnuItm, frmMain);
                                    }
                                    break;

                                case "DataGridView":
                                    System.Windows.Forms.DataGridView dgw1;
                                    System.Windows.Forms.DataGridViewColumn _column1;
                                    dgw1 = (System.Windows.Forms.DataGridView)splctrl;
                                    for (int b = 0; b < dgw1.Columns.Count; b++)
                                    {
                                        _column1 = dgw1.Columns[b];
                                        strText = f_FillLanDescriptions(_column1.Name, frmMain.tDesc);
                                        if (strText != "")
                                        {
                                            _column1.HeaderText = strText;
                                        }
                                    }
                                    break;

                                case "Label":
                                    strText = f_FillLanDescriptions(splctrl.Name, frmMain.tDesc);
                                    if (strText != "")
                                    {
                                        splctrl.Text = strText;
                                    }
                                    break;

                                case "Button":
                                    strText = f_FillLanDescriptions(splctrl.Name, frmMain.tDesc);
                                    if (strText != "")
                                    {
                                        splctrl.Text = strText;
                                    }
                                    break;

                                case "GroupBox":
                                    strText = f_FillLanDescriptions(splctrl.Name, frmMain.tDesc);
                                    if (strText != "")
                                    {
                                        splctrl.Text = strText;
                                    }
                                    System.Windows.Forms.GroupBox _groupbox = (System.Windows.Forms.GroupBox)splctrl;
                                    for (int f = 0; f < _groupbox.Controls.Count; f++)
                                    {
                                        System.Windows.Forms.Control _grpctrl = _groupbox.Controls[f];
                                        switch (_grpctrl.GetType().Name)
                                        {
                                            case "MenuStrip":
                                                System.Windows.Forms.ToolStripMenuItem mnuItm2;
                                                for (int i = 0; i < frmForm.MainMenuStrip.Items.Count; i++)
                                                {
                                                    mnuItm2 = (System.Windows.Forms.ToolStripMenuItem)frmForm.MainMenuStrip.Items[i];
                                                    strText = f_FillLanDescriptions(mnuItm2.Name, frmMain.tDesc);
                                                    if (strText != "")
                                                    {
                                                        mnuItm2.Text = strText;
                                                    }
                                                    f_FillMnuSubItems(mnuItm2, frmMain);
                                                }
                                                break;

                                            case "DataGridView":
                                                System.Windows.Forms.DataGridView dgw3;
                                                System.Windows.Forms.DataGridViewColumn _column3;
                                                dgw3 = (System.Windows.Forms.DataGridView)_grpctrl;
                                                for (int b = 0; b < dgw3.Columns.Count; b++)
                                                {
                                                    _column3 = dgw3.Columns[b];
                                                    strText = f_FillLanDescriptions(_column3.Name, frmMain.tDesc);
                                                    if (strText != "")
                                                    {
                                                        _column3.HeaderText = strText;
                                                    }
                                                }
                                                break;

                                            case "Label":
                                                strText = f_FillLanDescriptions(_grpctrl.Name, frmMain.tDesc);
                                                if (strText != "")
                                                {
                                                    _grpctrl.Text = strText;
                                                }
                                                break;

                                            case "Button":
                                                strText = f_FillLanDescriptions(_grpctrl.Name, frmMain.tDesc);
                                                if (strText != "")
                                                {
                                                    _grpctrl.Text = strText;
                                                }
                                                break;

                                            case "GroupBox":
                                                strText = f_FillLanDescriptions(_grpctrl.Name, frmMain.tDesc);
                                                if (strText != "")
                                                {
                                                    _grpctrl.Text = strText;
                                                }
                                                break;
                                        }
                                    }
                                    break;
                            }
                        }
                        for (int e = 0; e < _splcontainer.Panel2.Controls.Count; e++)
                        {
                            System.Windows.Forms.Control splctrl = _splcontainer.Panel2.Controls[e];
                            switch (splctrl.GetType().Name)
                            {
                                case "MenuStrip":
                                    System.Windows.Forms.ToolStripMenuItem mnuItm;
                                    for (int i = 0; i < frmForm.MainMenuStrip.Items.Count; i++)
                                    {
                                        mnuItm = (System.Windows.Forms.ToolStripMenuItem)frmForm.MainMenuStrip.Items[i];
                                        strText = f_FillLanDescriptions(mnuItm.Name, frmMain.tDesc);
                                        if (strText != "")
                                        {
                                            mnuItm.Text = strText;
                                        }
                                        f_FillMnuSubItems(mnuItm, frmMain);
                                    }
                                    break;

                                case "DataGridView":
                                    System.Windows.Forms.DataGridView dgw1;
                                    System.Windows.Forms.DataGridViewColumn _column1;
                                    dgw1 = (System.Windows.Forms.DataGridView)splctrl;
                                    for (int b = 0; b < dgw1.Columns.Count; b++)
                                    {
                                        _column1 = dgw1.Columns[b];
                                        strText = f_FillLanDescriptions(_column1.Name, frmMain.tDesc);
                                        if (strText != "")
                                        {
                                            _column1.HeaderText = strText;
                                        }
                                    }
                                    break;

                                case "Label":
                                    strText = f_FillLanDescriptions(splctrl.Name, frmMain.tDesc);
                                    if (strText != "")
                                    {
                                        splctrl.Text = strText;
                                    }
                                    break;

                                case "Button":
                                    strText = f_FillLanDescriptions(splctrl.Name, frmMain.tDesc);
                                    if (strText != "")
                                    {
                                        splctrl.Text = strText;
                                    }
                                    break;

                                case "GroupBox":
                                    strText = f_FillLanDescriptions(splctrl.Name, frmMain.tDesc);
                                    if (strText != "")
                                    {
                                        splctrl.Text = strText;
                                    }
                                    System.Windows.Forms.GroupBox _groupbox = (System.Windows.Forms.GroupBox)splctrl;
                                    for (int f = 0; f < _groupbox.Controls.Count; f++)
                                    {
                                        System.Windows.Forms.Control _grpctrl = _groupbox.Controls[f];
                                        switch (_grpctrl.GetType().Name)
                                        {
                                            case "MenuStrip":
                                                System.Windows.Forms.ToolStripMenuItem mnuItm3;
                                                for (int i = 0; i < frmForm.MainMenuStrip.Items.Count; i++)
                                                {
                                                    mnuItm3 = (System.Windows.Forms.ToolStripMenuItem)frmForm.MainMenuStrip.Items[i];
                                                    strText = f_FillLanDescriptions(mnuItm3.Name, frmMain.tDesc);
                                                    if (strText != "")
                                                    {
                                                        mnuItm3.Text = strText;
                                                    }
                                                    f_FillMnuSubItems(mnuItm3, frmMain);
                                                }
                                                break;

                                            case "DataGridView":
                                                System.Windows.Forms.DataGridView dgw4;
                                                System.Windows.Forms.DataGridViewColumn _column4;
                                                dgw4 = (System.Windows.Forms.DataGridView)_grpctrl;
                                                for (int b = 0; b < dgw4.Columns.Count; b++)
                                                {
                                                    _column4 = dgw4.Columns[b];
                                                    strText = f_FillLanDescriptions(_column4.Name, frmMain.tDesc);
                                                    if (strText != "")
                                                    {
                                                        _column4.HeaderText = strText;
                                                    }
                                                }
                                                break;

                                            case "Label":
                                                strText = f_FillLanDescriptions(_grpctrl.Name, frmMain.tDesc);
                                                if (strText != "")
                                                {
                                                    _grpctrl.Text = strText;
                                                }
                                                break;

                                            case "Button":
                                                strText = f_FillLanDescriptions(_grpctrl.Name, frmMain.tDesc);
                                                if (strText != "")
                                                {
                                                    _grpctrl.Text = strText;
                                                }
                                                break;

                                            case "GroupBox":
                                                strText = f_FillLanDescriptions(_grpctrl.Name, frmMain.tDesc);
                                                if (strText != "")
                                                {
                                                    _grpctrl.Text = strText;
                                                }
                                                break;
                                        }
                                    }
                                    break;
                            }
                        }    
                        break;

                    case "GroupBox":
                        strText = f_FillLanDescriptions(ctrl.Name, frmMain.tDesc);
                        if (strText != "")
                        {
                            ctrl.Text = strText;
                        }
                        System.Windows.Forms.GroupBox _groupbox1 = (System.Windows.Forms.GroupBox)ctrl;
                        for (int f = 0; f < _groupbox1.Controls.Count; f++)
                        {
                            System.Windows.Forms.Control _grpctrl = _groupbox1.Controls[f];
                            switch (_grpctrl.GetType().Name)
                            {
                                case "MenuStrip":
                                    System.Windows.Forms.ToolStripMenuItem mnuItm;
                                    for (int i = 0; i < frmForm.MainMenuStrip.Items.Count; i++)
                                    {
                                        mnuItm = (System.Windows.Forms.ToolStripMenuItem)frmForm.MainMenuStrip.Items[i];
                                        strText = f_FillLanDescriptions(mnuItm.Name, frmMain.tDesc);
                                        if (strText != "")
                                        {
                                            mnuItm.Text = strText;
                                        }
                                        f_FillMnuSubItems(mnuItm, frmMain);
                                    }
                                    break;

                                case "DataGridView":
                                    System.Windows.Forms.DataGridView dgw1;
                                    System.Windows.Forms.DataGridViewColumn _column1;
                                    dgw1 = (System.Windows.Forms.DataGridView)_grpctrl;
                                    for (int b = 0; b < dgw1.Columns.Count; b++)
                                    {
                                        _column1 = dgw1.Columns[b];
                                        strText = f_FillLanDescriptions(_column1.Name, frmMain.tDesc);
                                        if (strText != "")
                                        {
                                            _column1.HeaderText = strText;
                                        }
                                    }
                                    break;

                                case "Label":
                                    strText = f_FillLanDescriptions(_grpctrl.Name, frmMain.tDesc);
                                    if (strText != "")
                                    {
                                        _grpctrl.Text = strText;
                                    }
                                    break;

                                case "Button":
                                    strText = f_FillLanDescriptions(_grpctrl.Name, frmMain.tDesc);
                                    if (strText != "")
                                    {
                                        _grpctrl.Text = strText;
                                    }
                                    break;

                                case "GroupBox":
                                    strText = f_FillLanDescriptions(_grpctrl.Name, frmMain.tDesc);
                                    if (strText != "")
                                    {
                                        _grpctrl.Text = strText;
                                    }
                                    break;
                            }
                        }
                        break;
                }
                
            }

        }
...
Рейтинг: 0 / 0
Спрятать элементы формы
    #37400232
Фотография Deft
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
izoldov-roskiniуточняю, нужно сделать элемент невидимым в не зависимости от того на каком контейнере он находится. То что Вы написали работает только если педалька лежит на форме, а вот если она лежит на панели, которая лежит на форме - то ничего не работает. Может есть способ найти элемент по имени на форме?
Правильно сделать так:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
    Public Function FindControlByName(ByVal parent As Control, ByVal controlName As String) As Control
        Dim pretendent As Control = parent.Controls(controlName)
        If pretendent IsNot Nothing Then
            Return pretendent
        Else
            If parent.HasChildren Then
                For Each cntrl As Control In parent.Controls
                    pretendent = FindControlByName(cntrl, controlName)
                    If pretendent IsNot Nothing Then Return pretendent
                Next
            End If
        End If

        Return pretendent
    End Function
Пользоваться так:
Код: plaintext
    Dim pic As Control = FindControlByName(Me, "PictureBox2")
...
Рейтинг: 0 / 0
Спрятать элементы формы
    #37400241
Фотография Deft
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
DeftПользоваться так:
Код: plaintext
    Dim pic As Control = FindControlByName(Me, "PictureBox2")

Первый параметр "Форма", чтобы перебрать все контролы
...
Рейтинг: 0 / 0
Спрятать элементы формы
    #37400276
Фотография Где-то в степи
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
izoldov-roskini,

рекурсия
...
Рейтинг: 0 / 0
Спрятать элементы формы
    #37400326
ViPRos
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
pf,

ну ты даешь :)
...
Рейтинг: 0 / 0
Спрятать элементы формы
    #37400478
izoldov-roskini
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
всем спасибо, смысл понятен. На самом деле рекурсию я пробовал, просто много условий писать приходится, но без них никуда. За большой кусок кода спасибо, в принципе то что надо. Просто думал что в .Net есть более элегантные пути решения подобной проблемы
...
Рейтинг: 0 / 0
Спрятать элементы формы
    #37400528
Фотография Cat2
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Модератор форума
izoldov-roskiniуточняю, нужно сделать элемент невидимым в не зависимости от того на каком контейнере он находится. То что Вы написали работает только если педалька лежит на форме, а вот если она лежит на панели, которая лежит на форме - то ничего не работает. Может есть способ найти элемент по имени на форме?
А как же

Код: plaintext
button1.Visible = false
...
Рейтинг: 0 / 0
Спрятать элементы формы
    #37400530
Фотография Cat2
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Модератор форума
ViPRospf,

ну ты даешь :)
И не говори
...
Рейтинг: 0 / 0
Спрятать элементы формы
    #37400532
Фотография Cat2
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Модератор форума
pfВот функция, которая заполняет все подписи на форме (для многоязычности)
Вы почитайте про локализацию для многоязычности приложения.
...
Рейтинг: 0 / 0
Спрятать элементы формы
    #37400966
Фотография pf
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Cat2pfВот функция, которая заполняет все подписи на форме (для многоязычности)
Вы почитайте про локализацию для многоязычности приложения.

Обязательно почитаю
...
Рейтинг: 0 / 0
Спрятать элементы формы
    #37403029
izoldov-roskini
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Ну с элементами формы вроде как все понятно, а вот что делать к компонентами, которые лежат не на форме, например ContextMenuStrip, как до него добраться?
...
Рейтинг: 0 / 0
Спрятать элементы формы
    #37403507
Фотография fortibransa
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
izoldov-roskiniНу с элементами формы вроде как все понятно, а вот что делать к компонентами, которые лежат не на форме, например ContextMenuStrip, как до него добраться?исчи в Компонентах
pf +100500
Локализация воопчето просто делается
Свойство формы Localizable ставишь в true
Выбираешь Language и все, пишешь какие надо букавки, размер и положение а есчо справо налево слево направо.
При создании нового контрола не забывай перключатся на язык Default.
Коли треба переключать открытую форму то вот функция.
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
        public static void localizeForm(Form someForm, System.Globalization.CultureInfo cultureInfo)
        {
            Type someFormType = someForm.GetType();
            ResourceManager res = new ResourceManager(someFormType);

            //зададим список свойств объектов, которые будем извлекать из файла ресурсов  
            string[] properties = { "Text", "HeaderText" , "Size", "Location" };

            foreach (string propertyName in properties)
            {
                //выбор всех свойств класса формы, извлечение из файла ресурсов значения, и их установка  
                foreach (FieldInfo fieldInfo in someFormType.GetFields(BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Instance))
                {
                    PropertyInfo propertyInfo = fieldInfo.FieldType.GetProperty(propertyName);
                    if (propertyInfo == null)
                        continue;
                    object objProperty = res.GetObject(fieldInfo.Name + '.' + propertyInfo.Name, cultureInfo);
                    if (objProperty == null) continue;
                        object field = fieldInfo.GetValue(someForm);
                        if (field != null)
                            propertyInfo.SetValue(field, objProperty, null);
                }
                //код для установки свойств самих форм  
               //тут лучше не менять размеры а то формы принимает размеры как в студии при разработке
                if (propertyName == "Text")
                {
                    PropertyInfo propertyInfo1 = someFormType.GetProperty(propertyName);
                    if (propertyInfo1 == null)
                        continue;
                    object objProperty1 = res.GetObject("$this." + propertyInfo1.Name, cultureInfo);
                    if (objProperty1 == null) continue;
                    propertyInfo1.SetValue(someForm, objProperty1, null);
                }
            }
        }
установка языка делается вот так
Код: plaintext
1.
2.
3.
4.
    //це для форматирования можно не ставить будет как на компутере
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
//це для букавок
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");
...
Рейтинг: 0 / 0
Спрятать элементы формы
    #37404093
Фотография Cat2
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Модератор форума
izoldov-roskiniНу с элементами формы вроде как все понятно, а вот что делать к компонентами, которые лежат не на форме, например ContextMenuStrip, как до него добраться?
Они все равно определены в классе формы.

ContextMenuStrip.Items.Clear();
...
Рейтинг: 0 / 0
Период между сообщениями больше года.
Спрятать элементы формы
    #39614948
tvTheBest
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Я посмотрел на коды, которые тут пишут. Народ, зачем такие большие коды, если спрятать элемент формы можно проще, если использовать CheckBox (это рядом с элементом Button, а именно справа от него). Вот как это делается:
Нам нужно поставить элементы: CheckBox(буду называть chk1), Button(буду называть btn1) и Label(буду называть lbl1,на нём я наведу пример).
Теперь в форме нажимаем двойным щелчком на btn1 и пишем в юните:

procedure TForm1.btn1Click(Sender: TObject);
begin
If chk1.Checked
then lbl1.Hide
else lbl1.Show
end;

Вот и всё. Теперь, если вы поставили галочку в chk1, то по нажатию кнопки lbl1 будет "исчезать". Так же можно провернуть, если вы хотите через одну форму (Form2, например) хотите скрыть элемент в другой (Form1). Вот как:

procedure TForm2.btn1Click(Sender: TObject);
begin
If chk1.Checked
then Form1.lbl1.Hide
else Form1.lbl1.Show
end;
...
Рейтинг: 0 / 0
Спрятать элементы формы
    #39615045
Фотография skyANA
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
tvTheBest,

а сколько Вам лет, если не секрет?
...
Рейтинг: 0 / 0
19 сообщений из 19, страница 1 из 1
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / Спрятать элементы формы
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]