Очень полезная статья "Генерируем OfficeOpenXML-документы за 5 минут"
Рекомендую.
Санкции не работают
месяц назад
public partial class Form1: Form
{
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
private static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
private static extern IntPtr GetShellWindow();
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowRect(IntPtr hwnd, out RECT rc);
private IntPtr desktopHandle; //Хэндл рабочего стола
private IntPtr shellHandle; //Хэндл оболочки
public Form1()
{
InitializeComponent();
this.TopMost = true;
//Получаем хэндлы окон оболочки и рабочего стола
desktopHandle = GetDesktopWindow();
shellHandle = GetShellWindow();
}
public bool isThereFullScreenWindow()
{
//Detect if the current app is running in full screen
bool runningFullScreen = false;
RECT appBounds;
Rectangle screenBounds;
IntPtr hWnd;
//get the dimensions of the active window
hWnd = GetForegroundWindow();
if (hWnd != null && !hWnd.Equals(IntPtr.Zero))
{
//Check we haven't picked up the desktop or the shell
if (!(hWnd.Equals(desktopHandle) || hWnd.Equals(shellHandle)))
{
GetWindowRect(hWnd, out appBounds);
//determine if window is fullscreen
screenBounds = Screen.FromHandle(hWnd).Bounds;
if ((appBounds.Bottom - appBounds.Top) == screenBounds.Height && (appBounds.Right - appBounds.Left) == screenBounds.Width)
{
runningFullScreen = true;
}
}
}
return runningFullScreen;
}
Ну а потом уже все просто:
if (!isThereFullScreenWindow())
this.TopMost = true;
else
this.TopMost = false;
this.FormBorderStyle = FormBorderStyle.SizableToolWindow;
this.ShowInTaskbar = false;
2. Если же нужна форма без границы и без кнопок свернуть/развернуть/закрыть, то надо делать так:
this.FormBorderStyle = FormBorderStyle.None;
this.ShowInTaskbar = false;
...
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
// turn on WS_EX_TOOLWINDOW style bit
cp.ExStyle |= 0x80;
return cp;
}
}
0 | MM/dd/yyyy | 08/22/2006 |
1 | dddd, dd MMMM yyyy | Tuesday, 22 August 2006 |
2 | dddd, dd MMMM yyyy | HH:mm Tuesday, 22 August 2006 06:30 |
3 | dddd, dd MMMM yyyy | hh:mm tt Tuesday, 22 August 2006 06:30 AM |
4 | dddd, dd MMMM yyyy | H:mm Tuesday, 22 August 2006 6:30 |
5 | dddd, dd MMMM yyyy | h:mm tt Tuesday, 22 August 2006 6:30 AM |
6 | dddd, dd MMMM yyyy HH:mm:ss | Tuesday, 22 August 2006 06:30:07 |
7 | MM/dd/yyyy HH:mm | 08/22/2006 06:30 |
8 | MM/dd/yyyy hh:mm tt | 08/22/2006 06:30 AM |
9 | MM/dd/yyyy H:mm | 08/22/2006 6:30 |
10 | MM/dd/yyyy h:mm tt | 08/22/2006 6:30 AM |
10 | MM/dd/yyyy h:mm tt | 08/22/2006 6:30 AM |
10 | MM/dd/yyyy h:mm tt | 08/22/2006 6:30 AM |
11 | MM/dd/yyyy HH:mm:ss | 08/22/2006 06:30:07 |
12 | MMMM dd | August 22 |
13 | MMMM dd | August 22 |
14 | yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK | 2006-08-22T06:30:07.7199222-04:00 |
15 | yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK | 2006-08-22T06:30:07.7199222-04:00 |
16 | ddd, dd MMM yyyy HH':'mm':'ss 'GMT' | Tue, 22 Aug 2006 06:30:07 GMT |
17 | ddd, dd MMM yyyy HH':'mm':'ss 'GMT' | Tue, 22 Aug 2006 06:30:07 GMT |
18 | yyyy'-'MM'-'dd'T'HH':'mm':'ss | 2006-08-22T06:30:07 |
19 | HH:mm | 06:30 |
20 | hh:mm tt | 06:30 AM |
21 | H:mm | 6:30 |
22 | h:mm tt | 6:30 AM |
23 | HH:mm:ss | 06:30:07 |
24 | yyyy'-'MM'-'dd HH':'mm':'ss'Z' | 2006-08-22 06:30:07Z |
25 | dddd, dd MMMM yyyy HH:mm:ss | Tuesday, 22 August 2006 06:30:07 |
26 | yyyy MMMM | 2006 August |
27 | yyyy MMMM | 2006 August |
- В свойствах формы прописать свойство keypreview равным true
- В KeyUp добавить следующий обработчик событий:
private void form1_KeyUp(object sender, KeyEventArgs e)
{
//if user clicked Shift+Ins or Ctrl+V (paste from clipboard)
if ((e.Shift && e.KeyCode == Keys.Insert) || (e.Control && e.KeyCode == Keys.V))
{
char[] rowSplitter = { '\r', '\n' };
char[] columnSplitter = { '\t' };
//get the text from clipboard
IDataObject dataInClipboard = Clipboard.GetDataObject();
string stringInClipboard = (string)dataInClipboard.GetData(DataFormats.Text);
//split it into lines
string[] rowsInClipboard = stringInClipboard.Split(rowSplitter, StringSplitOptions.RemoveEmptyEntries);
//get the row and column of selected cell in grid
int r = grid.SelectedCells[0].RowIndex;
int c = grid.SelectedCells[0].ColumnIndex;
//add rows into grid to fit clipboard lines
if (grid.Rows.Count < (r + rowsInClipboard.Length))
grid.Rows.Add(r + rowsInClipboard.Length - grid.Rows.Count);
// loop through the lines, split them into cells and place the values in the corresponding cell.
for (int iRow = 0; iRow < rowsInClipboard.Length; iRow++)
{
//split row into cell values
string[] valuesInRow = rowsInClipboard[iRow].Split(columnSplitter);
//cycle through cell values
for (int iCol = 0; iCol < valuesInRow.Length; iCol++)
{
//assign cell value, only if it within columns of the grid
if (grid.ColumnCount - 1 >= c + iCol)
grid.Rows[r + iRow].Cells[c + iCol].Value = valuesInRow[iCol];
}
}
}
}