Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
public class DataGridViewSelectAllCheckBoxHeaderCell : DataGridViewColumnHeaderCell
{
protected static class CheckBoxHeaderCellRenderer
{
private static readonly VisualStyleElement CheckBoxElement
@KOZ60
KOZ60 / DataGridViewWithFooter.cs
Last active September 25, 2023 22:53
DataGridViewWithFooter
using System;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
[DesignerCategory("code") ]
public class DataGridViewWithFooter : DataGridView
@KOZ60
KOZ60 / ref string.md
Last active September 25, 2023 07:47
ref string

How to pass a ref string from C# to a DLL

C#

[DllImport("SampleDLL.Dll", CharSet = CharSet.None)]
[return: MarshalAs(UnmanagedType.BStr)]
extern public static string StringTest(
    [MarshalAs(UnmanagedType.BStr)] ref string refString
    );
@KOZ60
KOZ60 / RestrictText.cs
Last active April 22, 2024 09:32
RestrictText.cs
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
public class RestrictText : TextBox
{
private const char BACKSPACE = '\b'; // Backspace
private const char CTRL_A = '\x01'; // CTRL+A(Select All)
@KOZ60
KOZ60 / RestrictText.vb
Created September 29, 2023 19:54
RestrictText.vb
Option Strict On
Imports System
Imports System.Diagnostics
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Windows.Forms
Public Class RestrictText
Inherits TextBox
Private Const CTRL_A As Char = ChrW(&H1) ' CTRL+A (Select All)
@KOZ60
KOZ60 / LowLevelKeyboardHook.vb
Last active October 1, 2023 13:51
LowLevelKeyboardHook.vb
Imports System.ComponentModel
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
<DesignerCategory("code")>
<DefaultEvent("KeyDown")>
Public Class LowLevelKeyboardHook
Inherits Component
Private HookHandle As IntPtr = IntPtr.Zero
@KOZ60
KOZ60 / Hotkey.vb
Last active October 1, 2023 07:28
Hotkey.vb
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
<DefaultEvent("HotkeyPress")>
Public Class Hotkey
Inherits Component
@KOZ60
KOZ60 / NetOfficeFw.md
Last active October 23, 2023 23:49
NetOfficeFw

Would you like to try using NetOfficeFw.Excel? You can get it from nuget.

https://www.nuget.org/packages/NetOfficeFw.Excel

  1. There is no need to write Marshal.ReleaseComObject at all. All objects implement IDisposable, and when you Dispose them, they are released internally using ReleaseComObject. Also, if you Dispose the top level NetOffice.ExcelApi.Application, all the objects under it will be released.

  2. Since it is late binding, it does not depend on the Office version.

@KOZ60
KOZ60 / ClipboardMonitor.md
Last active October 1, 2023 22:24
Clipboard Monitor

1.SetClipboardViewer

Imports System.Runtime.InteropServices

Public Class Form1

    Private hwndNextChain As IntPtr

    Public Sub New()
@KOZ60
KOZ60 / PlayOfInheritance.cs
Last active October 6, 2023 16:58
PlayOfInheritance
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Proxies;
using System.Diagnostics;
static class UTL
{