Graphics in C# on macOS

The Einhugur framework has similarities to Xojo in many ways

It has a Canvas, just like Xojo

And when you use its paint event you can do many of the same things like drawing text and shapes and pictures.

We can add a canvas just like other controls. And we can implement the paint event in the same way.… Read the rest

Hanging on by a …

THREAD !!!!!!!!!!

yeah ok bad joke. I’ve been so dang busy with studying and work that I just haven’t had a reasonable chance to write any updates for the C# on macOS series.

But now that my Canadian Ski Patrol exams are done I can get back to some fun.

How to make our little project use a thread instead of a timer.… Read the rest

Using other databases in C#

A new version of the Einhugur C# UI framework was released a short while ago.

Since the framework is still literally a work in progress some changes an dupes are to be expected. Listbox now exists and its constructor now takes an array of column titles as well as the initial dimensions. So you may need to update code like


list = new ListBox(10, 20, 80, 20 );

to add a new last parameter

list = new ListBox(10, 20, 80, 20, new string[] {"col 1", "col 2"} );

to set the column titles.… Read the rest

Sort like Finder

Sometimes you want to be able to sort things in the same fashion as the Finder. This method when used as the comparison function for the Arry.Sort( delegate) form of sorting will do that

Public Function CompareLikeFinder(firstString as string, secondString as String) as integer
  #If targetMacOS
    // // 
    // // typedef NS_CLOSED_ENUM(NSInteger, NSComparisonResult) {
    // // NSOrderedAscending = -1L,
    // // NSOrderedSame,
    // // NSOrderedDescending
    // // };
    // 
    // // this gives us "Finder like" comparisons
    
    // -[NSString localizedStandardCompare:].
Read the rest

Is full keyboard access on ?

Sometimes its useful to be able to be able to tell your user if they need to enable full keyboard access

You can tell if its enabled with this method

Public Function FullKeyboardAccessEnabled() as Boolean
  #If TargetMacOS
    Try
      Declare Function NSClassFromString Lib "Cocoa" (name As CFStringRef) As Ptr
      Declare Function GetSharedApplication Lib "AppKit" Selector "sharedApplication" (target As Ptr) As Ptr
      Declare Function IsFullKeyboardAccessEnabled Lib "AppKit" Selector "isFullKeyboardAccessEnabled" (target As Ptr) As Boolean
      
      Dim AppClass As Ptr = NSClassFromString("NSApplication")
      If AppClass <Nil Then
        Dim AppObject As Ptr = GetSharedApplication(AppClass)
        If AppObject <Nil Then
          Return IsFullKeyboardAccessEnabled(AppObject)
        End If
      End If
    Catch Err As RuntimeException
      Return False
    End Try
  #endif
  
  
  // windows & linux can tab to EVERY control anyway
  return true
End Function

Read the rest

Opting in or out of Windows AutoTabbing

macOS adopted an interesting behaviour some time ago where when you opened a new window in an application. It would default to opening a new tab in the window instead of opening a new window.

If your application could not deal with this and the user had the preference in System Preferences > Dock > Prefer Tabs when opening documents set to Always then it could cause your app issues.… Read the rest

Showing a file in the Finder

This has probably been posted in the forums. Its just not always easy to find.

Declare Function NSClassFromString Lib "Cocoa" (name As CFStringRef) As Ptr
Declare Function sharedWorkspace Lib "AppKit" selector "sharedWorkspace" ( obj As ptr ) As ptr
Declare Function selectFile Lib "AppKit" selector "selectFile:inFileViewerRootedAtPath:" ( obj As ptr, fPath As CFStringRef, rootFullPath As CFStringRef ) As Boolean
Dim workspace As ptr = sharedWorkspace( NSClassFromString( "NSWorkspace" ) )

Call selectFile( workspace, f.NativePath,
Read the rest

Simple but really useful alternate menus

macOS supports the notion of Alternate menus. One that even once you have opened the menu you can toggle between their textual description and short cut by pressing the Option Key or another modifier like Shift or Control.

And you can even set up several so pressing Shift is one, Shift + Ctrl is another, and Option is yet another.… Read the rest