0

I am using Xamarin.Mac to develop a MacOS application with C#. I want to print(in the printer) a table, and I am using the print() function to do this. However, when I use this function it only prints what it is showing on the screen.

Apparently, it happens because the print function only prints the section of the NSView that appears on the screen.

I have found some solutions to this issue using Swift language, but I am not sure how to convert the code to C#.

In my code, SubviewCompanyController is my class which inherits from AppKit.NSViewController and it also has my table.

private NSViewController SubviewController = null;
.
.
.
var controllerCompany = SubviewController as SubviewCompanyController;
controllerCompany.View.Print(this);

1 Answers1

0

This is most likely because you are printing the parent NSView which will only print what's visible on the screen. You could call print directly on the NSTableView:

private void Print(NSObject sender)
{
    this.tableView.Print(sender); // Where this.tableView in an NSTableView
}

The end result is quite bare bones though.

Xavier
  • 41
  • 2
  • In your example, what is the sender? I tried to do your solution but did not print anything since my sender was a button. I also tried just writing this.Print(tableView) but it also prints only what is visible on the screen. – herybernal Aug 22 '19 at 20:28
  • The method Print is an action bound to an NSButton. So, just like you, sender is an NSButton. Regardless the sender should not change the behavior of the Print method itself. Are you sure you're not calling Print on the NSScrollView containing the NSTableView? This is quite an easy mistake to make when drag and dropping the wrong component in Xcode to create the action. – Xavier Aug 27 '19 at 12:52
  • I believe I am calling print on the NSTableView, but I am not sure. Probably you are right and I am calling print on the NSScrollView, but how would I know?In my view, I have the print button and a table. When I drop my table view in my view, it creates a scroll view. Inside the scroll view, there is a clip view and inside that it has my table view. – herybernal Aug 29 '19 at 18:43
  • When I use the print function, I put the name of my NSTableView. So I am not sure if I am doing something wrong. – herybernal Aug 29 '19 at 18:51
  • I'm assuming you created an outlet to get access to your NSTableView object in C#? If it is the case, you should be able to see the created properties in the *.Designer.cs file in Visual Studio. You should see the type of your property there. – Xavier Sep 03 '19 at 12:06
  • It is an NSTableView. If I put this.View.Print(sender) it shows only what it is visible on the screen but if I put this.tableView.Print(sender) it shows nothing, just a white paper. Is there a way you can send me a little project just showing how are you doing it. Thank you! – herybernal Sep 04 '19 at 21:08
  • Ah! Is it possible that you are using the Dark Theme? I actually do to, if so, notice how the table view contents is written in white. Well, when you actually try to print, it actually print with the text color of the NSTableView (but not the background color). So white on white. If this is your issue, you can probably change the text color just before printing and switching it back afterwards. Otherwise, if this is not your issue, I have no problem sending you a small sample app. – Xavier Sep 06 '19 at 12:18
  • That was the issue!!! I had the Dark theme and I changed it to the white theme and now " this.tableView.Print(sender); " prints the content of the table. I can't believe a small detail like that could affect my program. Thank you a lot Xavier!!! – herybernal Sep 07 '19 at 01:25
  • Glad to hear it! To be fair, I think it is kind of an overlook from Apple. If it is going to print on a white background, it should obviously not use the Dark Theme control text color. – Xavier Sep 08 '19 at 15:27