Click here to Skip to main content
15,886,110 members

Comments by Adérito Silva (Top 23 by date)

Adérito Silva 11-Aug-21 23:18pm View    
As far as I know, there is no easy way to do that. I can think of ways it would be possible, but I didn't put too much thought on it.

I believe it would be possible by hooking certain windows functions, including those responsible for interchanging Windows Messages.

Another way would be to display the contents of the 3rd party application window on your application (as if your application was a screen recorder) and send Windows Messages to the 3rd party application to simulate user input coming from your application. However, that would be complex and would require a lot of work.

Depending on how the specific 3rd party application handles its window size, you could send some Windows Messages to change its window type, after the application sets it itself. Then, it might be possible to send another Windows Message to set your own size and position to be within the bounds of your own application.

As a last resource, hacking the application executable might also work, but that would require some reverse engineering skill and may be violation of copyright or something.

Either way, doing that is hacky, is hard and may or may not work. As Gerry Schmitz also suggested, using a virtual machine to run the application or even a sandbox might be a valid solution.
Adérito Silva 2-Aug-21 16:02pm View    
And this is my App class, where FontSize is declared:

    public partial class App : Application
    {

        public double FontSize => 30.0;

    }
Adérito Silva 2-Aug-21 16:01pm View    
This is the code I'm using, which is working fine and the text doesn't get blurry:

        <Button x:Name="BtnSettings" Width="90" Height="30" Margin="200,14,0,0" Padding="6,3"
                HorizontalAlignment="Left" VerticalAlignment="Top"
                UseLayoutRounding="True" SnapsToDevicePixels="True"       
                FontSize="10">
            <Button.Content >
                <Viewbox x:Name="myViewbox"
                         SnapsToDevicePixels="True" 
                         Stretch="Uniform" StretchDirection="Both">
                    <TextBlock x:Name="myTextbox" Margin="0,-2,0,0"
                               FontFamily="Segoe UI">
                        <TextBlock.FontSize>
                            <MultiBinding>
                                <MultiBinding.Converter>
                                    <local:AverageConverter/>
                                </MultiBinding.Converter>
                                <Binding Source="{x:Static Application.Current}" Path="FontSize" Mode="OneWay"/>
                                <Binding Path="FontSize" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type Button}}"/>
                            </MultiBinding>
                        </TextBlock.FontSize>
                        FontSize =
                        <Run Text="{Binding FontSize, Mode=OneWay, 
                             RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TextBlock}}}"
                             FontWeight="Bold"/>;
                    </TextBlock>
                </Viewbox>
            </Button.Content>
        </Button>
Adérito Silva 2-Aug-21 15:45pm View    
Your bindings are working fine on my end. For example, I set the Application.Current.FontSize to 100 and the button FontSize to 10. My TextBlock FontSize is 55, which is the average of 10+100. The text gets blurry, because of the text options you are using. Set TextOptions.TextFormattingMode="Ideal" or remove text options all together. That works for me.

If you are still getting the same error on the converter, check your bindings again. For example, you are using camel case on the binding to 'Application.Current.fontSize'. Is it intended, or may it be a simple misspell? Because, that happens to me if I misspell it, as well.
Adérito Silva 1-Aug-21 17:23pm View    
Dude, I mean no offense, but that code is really messed up. As others have mentioned, you are not passing safe SQL commands, which would need to be correctly escaped before being sent to the database (parameterized). Also, you need a lot of error handling, or your application will stop working many times on the users. You also need data validation, which is needed to validate any user input, specially when that data is to be stored. Adding to that, the code is hard to read and to maintain; it has lack of separation of concerns, like DB stuff being done directly on event handlers and things like that.

It would be better to have a class dedicated only to database operations, with proper error handling that safely closes connections if something wrong happens, and handling UI operations in their own methods, away from business logic. As for input validation, you need to make sure that there is nothing a user can input or do in your application that can make it work incorrectly or even make it stop working at all.