Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); AppSettingsSection configSection = config.AppSettings; try { if (configSection != null) { if (configSection.IsReadOnly() == false && configSection.SectionInformation.IsLocked == false) { configSection.Settings["myKey"].Value = "newValue"; config.Save(); } } } catch (ConfigurationException ex) { MessageBox.Show(ex.Message, "Configuration Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
segunda-feira, dezembro 21, 2009
Alterando o app.config
terça-feira, dezembro 15, 2009
C# Process Show() Hide()
Aqui vai um código bem curto de como manipular o estado(Show/Hide) de um processo. O exemplo foi feito em uma aplicação windows e parte do código foi ocultada para simplificar.
Abaixo a tabela completa dos estados retirado do site DaniWeb:
0 SW_HIDE
1 SW_SHOWNORMAL
1 SW_NORMAL
2 SW_SHOWMINIMIZED
3 SW_SHOWMAXIMIZED
3 SW_MAXIMIZE
4 SW_SHOWNOACTIVATE
5 SW_SHOW
6 SW_MINIMIZE
7 SW_SHOWMINNOACTIVE
8 SW_SHOWNA
9 SW_RESTORE
10 SW_SHOWDEFAULT
11 SW_FORCEMINIMIZE
11 SW_MAX
using System.Diagnostics; using System.Runtime.InteropServices; namespace MyApp { public partial class frmApp : Form { private const int SW_HIDE = 0; private const int SW_RESTORE = 9; private int hWnd; [DllImport("User32")] private static extern int ShowWindow(int hwnd, int nCmdShow); private void btnShow_Click(object sender, EventArgs e) { //Seleciona o primeiro processo Process p = Process.GetProcesses()[0]; hWnd = (int)p.MainWindowHandle; ShowWindow(hWnd, SW_RESTORE); } } }Parte do exemplo foi retirado do site C# Corner
Abaixo a tabela completa dos estados retirado do site DaniWeb:
0 SW_HIDE
1 SW_SHOWNORMAL
1 SW_NORMAL
2 SW_SHOWMINIMIZED
3 SW_SHOWMAXIMIZED
3 SW_MAXIMIZE
4 SW_SHOWNOACTIVATE
5 SW_SHOW
6 SW_MINIMIZE
7 SW_SHOWMINNOACTIVE
8 SW_SHOWNA
9 SW_RESTORE
10 SW_SHOWDEFAULT
11 SW_FORCEMINIMIZE
11 SW_MAX
Assinar:
Postagens (Atom)