xtd 0.2.0
screenshot.cpp

shows how to fill ellipse in paint event using xtd::drawing::graphics::copy_from_screen.

Windows

macOS

Gnome

#include <xtd/xtd>
using namespace xtd;
using namespace xtd::drawing;
using namespace xtd::forms;
namespace screenshot_example {
class form1 : public form {
public:
form1() {
text("Screenshot");
client_size({380, 320});
screenshot_picture_box.size_mode(picture_box_size_mode::zoom);
screenshot_delay_label.auto_size(true);
screenshot_delay_numeric_up_down.anchor(anchor_styles::left|anchor_styles::top|anchor_styles::right);
hide_this_window_check_box.auto_size(true);
screenshot_button.anchor(anchor_styles::left|anchor_styles::bottom);
screenshot_button.click += {*this, &form1::on_screenshot_button_click};
save_screenshot_button.anchor(anchor_styles::left|anchor_styles::bottom);
save_screenshot_button.click += {*this, &form1::on_save_screenshot_button_click};
quit_button.click += {*this, &form1::close};
take_screen_shot_timer.tick += {*this, &form1::on_take_screen_shot_timer_tick};
take_new_screenshot();
}
private:
auto on_save_screenshot_button_click() -> void {
if (!screenshot_picture_box.image().has_value()) return;
auto dialog = save_file_dialog {};
dialog.filter("PNG image(*.png)|*.png");
dialog.file_name("untitled");
if (dialog.show_sheet_dialog(*this) == dialog_result::ok) screenshot_picture_box.image().value().save(dialog.file_name());
}
auto on_screenshot_button_click() -> void {
screenshot_button.enabled(false);
if (hide_this_window_check_box.checked()) hide();
take_screen_shot_timer.interval(time_span::from_seconds(screenshot_delay_numeric_up_down.value()));
take_screen_shot_timer.enabled(true);
}
auto on_take_screen_shot_timer_tick() -> void {
take_screen_shot_timer.enabled(false);
take_new_screenshot();
if (hide_this_window_check_box.checked()) show();
screenshot_button.enabled(true);
}
auto take_new_screenshot() -> void {
auto screenshot_bitmap = bitmap {screen::primary_screen().bounds().width, screen::primary_screen().bounds().height};
screenshot_bitmap.create_graphics().copy_from_screen({0, 0}, {0, 0}, screenshot_bitmap.size());
screenshot_picture_box.image(screenshot_bitmap);
}
picture_box screenshot_picture_box = picture_box::create(*this, point {20, 20}, {340, 120});
group_box options_group_box = group_box::create(*this, "Options", {20, 160}, {340, 94});
label screenshot_delay_label = label::create(options_group_box, "Screenshot Delay (sec.) :", {15, 18});
numeric_up_down screenshot_delay_numeric_up_down = numeric_up_down::create(options_group_box, 5, 0, 60, {190, 15}, {130, 25});
check_box hide_this_window_check_box = check_box::create(options_group_box, "Hide This Window", {15, 45});
button screenshot_button = button::create(*this, "New screenshot", {20, 270}, {130, 25});
button save_screenshot_button = button::create(*this, "Save screenshot", {165, 270}, {130, 25});
button quit_button = button::create(*this, "Quit", {310, 270}, {50, 25});
forms::timer take_screen_shot_timer;
};
}
auto main() -> int {
application::run(screenshot_example::form1 {});
}
Encapsulates a GDI+ bitmap, which consists of the pixel data for a graphics image and its attributes....
Definition bitmap.hpp:26
void copy_from_screen(const xtd::drawing::point &upper_left_source, const xtd::drawing::point &upper_left_destination, const xtd::drawing::size &block_region_size)
Performs a bit-block transfer of color data, corresponding to a rectangle of pixels,...
graphics create_graphics()
Creates the xtd::drawing::graphics for the image.
@ my_pictures
The My Pictures folder.
Definition environment.hpp:209
static xtd::string get_folder_path(environment::special_folder folder)
Gets the path to the system special folder that is identified by the specified enumeration.
Definition environment.hpp:613
static void run()
Begins running a standard application message loop on the current thread, without a form.
Represents a Windows button control.
Definition button.hpp:49
static button create()
A factory to create an xtd::forms::button.
Represents a Windows check_box.
Definition check_box.hpp:45
static check_box create()
A factory to create an xtd::forms::check_box.
virtual const xtd::string & filter() const noexcept
Gets the current file name filter string, which determines the choices that appear in the "Save as fi...
Represents a window or dialog box that makes up an application's user interface.
Definition form.hpp:54
Represents a Windows control that displays a frame around a group of controls with an optional captio...
Definition group_box.hpp:37
static group_box create()
A factory to create an xtd::forms::group_box.
Represents a standard Windows label.
Definition label.hpp:38
static label create()
A factory to create an xtd::forms::label.
Represents a standard Windows numeric up down.
Definition numeric_up_down.hpp:34
static numeric_up_down create()
A factory to create an xtd::forms::numeric_up_down.
Represents a standard Windows picture box.
Definition picture_box.hpp:34
static picture_box create()
A factory to create an xtd::forms::picture_box.
Prompts the user to select a location for saving a file. This class cannot be inherited.
Definition save_file_dialog.hpp:30
static screen primary_screen()
Gets the primary display.
Implements a timer that raises an event at user-defined intervals. This timer is optimized for use in...
Definition timer.hpp:38
static time_span from_seconds(double value)
Returns a xtd::time_spam that represents a specified number of seconds, where the specification is ac...
@ zoom
The size of the image is increased or decreased maintaining the size ratio.
Definition picture_box_size_mode.hpp:32
@ ok
The dialog box return value is OK (usually sent from a button labeled OK).
Definition dialog_result.hpp:47
@ bottom
Bind control edges to the bottom of its container.
Definition anchor_styles.hpp:25
@ right
Bind control edges to the right of its container.
Definition anchor_styles.hpp:29
@ left
Bind control edges to the left of its container.
Definition anchor_styles.hpp:27
@ top
Bind control edges to the top of its container.
Definition anchor_styles.hpp:23
@ hide
Hides minimized windows by moving them off the visible area of the screen.
Definition arrange_starting_position.hpp:33
The xtd::drawing namespace provides access to GDI+ basic graphics functionality. More advanced functi...
Definition actions_system_images.hpp:10
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition texts.hpp:217
Contains classes that represent ASCII and Unicode character encodings; abstract base classes for conv...
Definition basic_string_builder.hpp:16
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition point.hpp:54