I have two points, let's say the upper left and lower right corner of a rectangle, in C++ .Net. How do I create a System.Drawing.Rectangle structure from these two points in .net? This should be simple, am I missing something?
The Rectangle constructor only works with Point and Size given, and by giving separate integer values, which I don't take into count here. It does not work by giving two points.
A Size strucure also can not be created from two points in a simple way. Subtracting one point from another is not defined, which should give a Size, and I see no other function that does that.
So I have to write the functions for that by myself? It should just be there.
How do I create a rectangle from two points?
7.6k Views Asked by Emil Albert At
1
There are 1 best solutions below
Related Questions in C++
- How to immediately apply DISPLAYCONFIG_SCALING display scaling mode with SetDisplayConfig and DISPLAYCONFIG_PATH_TARGET_INFO
- Why can't I use templates members in its specialization?
- How to fix "Access violation executing location" when using GLFW and GLAD
- Dynamic array of structures in C++/ cannot fill a dynamic array of doubles in structure from dynamic array of structures
- How do I apply the interface concept with the base-class in design?
- File refuses to compile std::erase() even if using -std=g++23
- How can I do a successful map when the number of elements to be mapped is not consistent in Thrust C++
- Can std::bit_cast be applied to an empty object?
- Unexpected inter-thread happens-before relationships from relaxed memory ordering
- How i can move element of dynamic vector in argument of function push_back for dynamic vector
- Brick Breaker Ball Bounce
- Thread-safe lock-free min where both operands can change c++
- Watchdog Timer Reset on ESP32 using Webservers
- How to solve compiler error: no matching function for call to 'dmhFS::dmhFS()' in my case?
- Conda CMAKE CXX Compiler error while compiling Pytorch
Related Questions in .NET
- file download method in visual studio 2017
- Repository manager receives the wrong connection string in .net core
- MongoDb not connecting C#
- The current .NET SDK does not support targeting .NET Core 6.0. Brand new WPF Project VS Community 2022 17.9.5
- Why Scanning GSI on DynamoDb doesnt work as fast as expected when using CONTAINS?
- Are "blittable types" really unmanaged types for StructLayout Sequential
- Failed to fetch dynamically imported module on Blazor JS Interop
- Problem to upload several images per one request
- Implementing Azure AD B2C Authentication in .NET 8 Blazor Project (RenderMode: InteractiveAuto)
- Stripe connect payout - throws exceptions
- 'IOException: The cloud file provider is not running', when trying to delete 'cloud' folder
- Azure Application Insights Not Displaying Custom Logs for Azure Functions with .NET 8
- Convert C# DateTime.Ticks to Bigquery DateTime Format
- Socket.io nodejs server .NET connection
- Producer Batching Service Bus Vs Kafka
Related Questions in RECTANGLES
- CSS cube overlay
- How to fill rectangles in my PowerApps project?
- Looking for an approach to finding the minimum number of rectangles necessary in order to fill the occupied area of a 2D matrix?
- using powershell windows forms create a listview with Multi Line Headers
- FlxRect.getRotatedBounds not getting hitboxes correctly?
- How to find the inner half area of a rectangle
- How to handle collision after a diagonal movement with rectangles
- Find the Largest Area of Square Inside Two Rectangles(Intersection)
- Create rotated rect in dart
- How can I create a code for T and L Figures but not in a plot?
- D3C - White Sheet Wrong Answer on Case 11
- clipPath doesn't clip the symbol path on SVG rectangle
- how to find a rectangles corner when scaling by new corners X and Y?
- How can I create a folder using a rectangle in SwiftUI?
- Search all valid positions of a rectangle in map with obstacles
Related Questions in SYSTEM.DRAWING
- System.Drawing - DrawString text with emoji
- Need Help How To Draw Both Arabic And English Words Char By Char
- Using System.Drawing2D LinearGradientBrush to Fill Ellipse; Unexpected Results
- Get the collision side of colliding rectangles
- Draw arc in system.drawing C#
- Cross-platform System.Drawing.Bitmap in .NET 8?
- Having an issue writing a unit test for my shape drawing program, The type or namespace MainForm could not be found in the Test class
- Network printers not showing in PrinterSettings.InstalledPrinters
- Calc text width, JS vs Windows graphics
- C# Custom Shape
- System.ArgumentException System.Drawing.Graphics.GetHdc()
- Why is it not drawing an outline?
- Can't use System.Drawing in C# console application
- C#: Is there a possibility to change an image's pixel format before it's saved?
- How to change the color of the tab each time its selected in a powershell Windows Form?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
You can easily make a static method that converts your two points in to a size then have it call the constructor of rectangle that takes in a point and a size.
This answer is in C# syntax but you should easily be able to convert it to C++/cli syntax.
Addition: the original answer above will lead to a negative size
:
The rectangle will have a Width of
-100; So it should be:Or even better: if you don't want to bother about which of the two points is at TopLeft:
I did this in baby steps to make things easy to understand. Of course this can be optimized.