This is a preview version of Cyotek's blog and may be missing functionality and/or unstable. Please visit https://www.cyotek.com/blog for the current version of the blog.
If you encounter any problems using this preview site, please contact us with the details.

Posts tagged with 'api'

Migrating from Azure translation API version 2 to 3

c# api azure rest translate localization 0 Comments Downloads

Almost two years ago I wrote a post describing how to translate text using Azure cognitive services, however the API it uses is to be switched off and so I needed to migrate from the version 2 API to version 3.

Whilst most of the code I post on this blog is used in one form or another, I've been using the TranslationClient client presented in that article as-is for the past two years. OK, I changed the namespace. But otherwise it's identical.

Read More

Getting a window rectangle without the drop shadow

c# api win32 2 Comments

In my last article, I describe how to use the Win32 API to capture screenshots of the desktop. There was one frustrating problem with this however - when capturing an image based on the value of the Bounds property of a Form unexpected values were returned for the left position, width and height of the window, causing my screenshots to be too big.

I thought that was odd but as I wanted to be able to capture unmanaged windows in future then using Form.Bounds wasn't going to be possible anyway and I would have to use GetWindowRect. I'm sure that deep down in the Windows Forms code base it uses the same API so I was expecting to get the same "wrong" results, and I wasn't disappointed.

Read More

Capturing screenshots using C# and p/invoke

c# api win32 screenshot 2 Comments Downloads

I was recently updating some documentation and wanted to programmatically capture some screenshots of the application in different states. This article describes how you can easily capture screenshots in your own applications.

This article makes use of a number of Win32 API methods. Although you may not have much call to use them directly in day to day .NET (not to mention Microsoft wanting everyone to use universal "apps" these days), they are still extraordinarily useful and powerful.

Read More

Announcing MantisSharp, a .NET client for using the MantisBT REST API

c# api rest mantisbt mantissharp 3 Comments

I've released a new open source project named MantisSharp, a simple .NET client for working with the recently introduced REST API for Mantis Bug Tracker.

The library is just getting started and is missing various functions (hello documentation!) but it seems to be usable - as well as the WinForms sample browser that I was using for development testing, I also tested it in an ASP.NET MVC application, both locally and then remotely using the development version of cyotek.com.

Read More

Translating text with Azure cognitive services

c# api azure rest translate localization 1 Comments Downloads

Some time ago, I used the Bing Translator API to help create localization for some of our products. As Microsoft recently retired the Data Market used to provide this service it was high time to migrate to the replacement Cognitive Services API hosted on Azure. This article covers using the basics of Azure cognitive services to translate text using simple HTTP requests.

I'm going to assume you've already signed up for the Text Translation Cognitive Services API. If you haven't, you can find a step by step guide on the API documentation site. Just as with the original version, there's a free tier where you can translate 2 million characters per month.

Read More

Retrieving font and text metrics using C#

c# interop api GetTextMetrics TEXTMETRIC 0 Comments Downloads

In several of my applications, I need to be able to line up text, be it blocks of text using different fonts, or text containers of differing heights. As far as I'm aware, there isn't a way of doing this natively in .NET, however with a little platform invoke we can get the information we need to do it ourselves.

The GetTextMetrics metrics function is used to obtain metrics based on a font and a device context by populating a TEXTMETRICW structure.

Read More

Specifying custom text when using the LabelEdit functionality of a TreeView

c# winforms api treeview SendMessage TVM_GETEDITCONTROL WM_SETTEXT pinvoke 0 Comments Downloads

Recently I was updating a support tool that displays documents in raw form and allows editing of them. This tool is centred around a TreeView, and the Text property of each TreeNode is a concatenation of a name and one or more values.

The problem with this approach is if you wish to allow the nodes to be edited using the built in functionality you're in trouble as by default you can't actually influence the text that appears in the in-line editor. In other applications of a similar nature I used owner-drawn trees as I was using different styles for the name and the value. In this case, I just wanted the standard look.

Read More

Adding a horizontal scrollbar to a ComboBox using C#

c# winforms combobox horizontal scroll api 4 Comments Downloads

In our WebCopy application we decided to update the User Agent configuration to allow selection from a predefined list of common agents, but still allow the user to enter their own custom agent if required.

Rather than use two separate fields, we choose to use a ComboBox in simple mode, which is both a textbox and a listbox in a single control. This mode seems somewhat out of fashion, I think the only place I see it used is in the Font common dialog, virtually unchanged since Windows 3.1.

Read More